Commits

vmorsiani committed c2e0072

implemented equals, hashCode & toString on entities

Comments (0)

Files changed (5)

jticketing-core/src/main/java/org/wanna/jticketing/persistence/entity/PrivilegeEntity.java

 package org.wanna.jticketing.persistence.entity;
 
+import org.apache.commons.lang.builder.ToStringBuilder;
 import org.springframework.security.core.GrantedAuthority;
 
 import javax.persistence.*;
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
     private Long id;
+    @Column(nullable = false)
     private String name;
 
     public Long getId() {
     public String getAuthority() {
         return name;
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        PrivilegeEntity that = (PrivilegeEntity) o;
+
+        if (!name.equals(that.name)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this).
+                append("name", name).
+                toString();
+    }
 }

jticketing-core/src/main/java/org/wanna/jticketing/persistence/entity/TicketCategoryEntity.java

 package org.wanna.jticketing.persistence.entity;
 
+import org.apache.commons.lang.builder.ToStringBuilder;
+
 import javax.persistence.*;
 
 @Entity
     public void setName(String name) {
         this.name = name;
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        TicketCategoryEntity that = (TicketCategoryEntity) o;
+
+        if (!name.equals(that.name)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this).
+                append("name", name).
+                toString();
+    }
 }

jticketing-core/src/main/java/org/wanna/jticketing/persistence/entity/TicketEntity.java

 package org.wanna.jticketing.persistence.entity;
 
+import org.apache.commons.lang.builder.ToStringBuilder;
+
 import javax.persistence.*;
 import java.util.Set;
 
     public void setCategory(TicketCategoryEntity category) {
         this.category = category;
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        TicketEntity that = (TicketEntity) o;
+
+        if (reference != null ? !reference.equals(that.reference) : that.reference != null) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return reference != null ? reference.hashCode() : 0;
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this).
+                append("reference", reference).
+                toString();
+    }
 }

jticketing-core/src/main/java/org/wanna/jticketing/persistence/entity/TicketMessage.java

     public void setAuthor(UserEntity author) {
         this.author = author;
     }
+
+
 }

jticketing-core/src/main/java/org/wanna/jticketing/persistence/entity/UserGroupEntity.java

 package org.wanna.jticketing.persistence.entity;
 
+import org.apache.commons.lang.builder.ToStringBuilder;
+
 import javax.persistence.*;
 import java.util.Set;
 
     @Id
     @GeneratedValue(strategy = GenerationType.AUTO)
     private Long id;
+    @Column(nullable = false)
     private String name;
     @ManyToMany
     private Set<PrivilegeEntity> privileges;
     public Set<PrivilegeEntity> getPrivileges() {
         return privileges;
     }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        UserGroupEntity that = (UserGroupEntity) o;
+
+        if (!name.equals(that.name)) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        return name.hashCode();
+    }
+
+    @Override
+    public String toString() {
+        return new ToStringBuilder(this).
+                append("name", name).
+                toString();
+    }
 }