From d4a2c17087e4cb90435c1fab4af2864347f7513d Mon Sep 17 00:00:00 2001 From: Kavoos Bojnourdi Date: Sat, 15 Aug 2015 16:10:13 +0200 Subject: [PATCH] Fix hashcode --- .../com/edf/gde/entities/AttributeGroup.java | 3 +-- .../src/java/com/edf/gde/entities/Chunk.java | 1 - .../src/java/com/edf/gde/entities/Group.java | 24 +++++++++++++++++ .../com/edf/gde/entities/GroupPermission.java | 27 +++++++++++++++++++ .../java/com/edf/gde/entities/Profile.java | 8 +++++- .../edf/gde/entities/ProfileAttribute.java | 1 - .../java/com/edf/gde/entities/UserGroup.java | 26 ++++++++++++++++++ 7 files changed, 85 insertions(+), 5 deletions(-) diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/AttributeGroup.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/AttributeGroup.java index 47502d2..e0b4e6f 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/AttributeGroup.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/AttributeGroup.java @@ -75,7 +75,7 @@ public class AttributeGroup implements Serializable { } @XmlTransient - public Collection getAttributeCollection() { + public Collection getAttributes() { return attributeCollection; } @@ -120,7 +120,6 @@ public class AttributeGroup implements Serializable { public int hashCode() { int hash = 7; hash = 79 * hash + (int) (this.id ^ (this.id >>> 32)); - hash = 79 * hash + Objects.hashCode(this.attributeCollection); return hash; } diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Chunk.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Chunk.java index 2fc2ac8..8e655e4 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Chunk.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Chunk.java @@ -146,7 +146,6 @@ public class Chunk implements Serializable { hash = 37 * hash + (int) (this.rank ^ (this.rank >>> 32)); hash = 37 * hash + Objects.hashCode(this.checksum); hash = 37 * hash + (int) (this.size ^ (this.size >>> 32)); - hash = 37 * hash + Arrays.hashCode(this.data); return hash; } diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Group.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Group.java index 9a35c47..5e3335b 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Group.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Group.java @@ -4,6 +4,7 @@ package com.edf.gde.entities; import com.edf.gde.transferables.GroupTO; +import java.util.Objects; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; @@ -69,4 +70,27 @@ public class Group { groupTO.setName(name); return groupTO; } + + @Override + public int hashCode() { + int hash = 5; + hash = 97 * hash + Objects.hashCode(this.id); + hash = 97 * hash + Objects.hashCode(this.name); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final Group other = (Group) obj; + if (!Objects.equals(this.id, other.id)) { + return false; + } + return true; + } } diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/GroupPermission.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/GroupPermission.java index de48b8d..9fac025 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/GroupPermission.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/GroupPermission.java @@ -1,6 +1,7 @@ package com.edf.gde.entities; import java.io.Serializable; +import java.util.Objects; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; @@ -79,4 +80,30 @@ public class GroupPermission implements Serializable { public void setMethodIndex(int methodIndex) { this.methodIndex = methodIndex; } + + @Override + public int hashCode() { + int hash = 3; + hash = 37 * hash + Objects.hashCode(this.id); + hash = 37 * hash + (int) (this.groupId ^ (this.groupId >>> 32)); + hash = 37 * hash + Objects.hashCode(this.serviceName); + hash = 37 * hash + this.methodIndex; + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final GroupPermission other = (GroupPermission) obj; + if (!Objects.equals(this.id, other.id)) { + return false; + } + return true; + } + } diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Profile.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Profile.java index c46b572..b25e824 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Profile.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/Profile.java @@ -95,6 +95,13 @@ public class Profile implements Serializable { public void setProfileAttributeCollection(Collection profileAttributeCollection) { this.profileAttributeCollection = profileAttributeCollection; } + + public void addProfileAttribute(ProfileAttribute attribute) { + if (profileAttributeCollection == null) { + setProfileAttributeCollection(new ArrayList()); + } + profileAttributeCollection.add(attribute); + } public static Profile fromProtileTO(EntityManager em, ProfileTO profileTO) { Profile profile = new Profile(); @@ -135,7 +142,6 @@ public class Profile implements Serializable { int hash = 3; hash = 83 * hash + Objects.hashCode(this.id); hash = 83 * hash + Objects.hashCode(this.name); - hash = 83 * hash + Objects.hashCode(this.profileAttributeCollection); return hash; } diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/ProfileAttribute.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/ProfileAttribute.java index 4ee3f2f..dd3a191 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/ProfileAttribute.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/ProfileAttribute.java @@ -136,7 +136,6 @@ public class ProfileAttribute implements Serializable { hash = 71 * hash + Objects.hashCode(this.name); hash = 71 * hash + Objects.hashCode(this.type); hash = 71 * hash + Objects.hashCode(this.mandatory); - hash = 71 * hash + Objects.hashCode(this.profile); return hash; } diff --git a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/UserGroup.java b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/UserGroup.java index 43c0fc0..244c9ae 100644 --- a/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/UserGroup.java +++ b/projects/GDE_App/GDE-ejb/src/java/com/edf/gde/entities/UserGroup.java @@ -3,6 +3,7 @@ */ package com.edf.gde.entities; +import java.util.Objects; import javax.persistence.Basic; import javax.persistence.Column; import javax.persistence.Entity; @@ -66,4 +67,29 @@ public class UserGroup { public void setGroupId(long groupId) { this.groupId = groupId; } + + @Override + public int hashCode() { + int hash = 5; + hash = 23 * hash + Objects.hashCode(this.id); + hash = 23 * hash + (int) (this.userId ^ (this.userId >>> 32)); + hash = 23 * hash + (int) (this.groupId ^ (this.groupId >>> 32)); + return hash; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + final UserGroup other = (UserGroup) obj; + if (!Objects.equals(this.id, other.id)) { + return false; + } + return true; + } + } -- 2.39.2