Skip to content

Commit

Permalink
Some work on GenericEntity and its subclasses: Enforce GenericPK != G…
Browse files Browse the repository at this point in the history
…enericEntity and GenericValue != GenericEntity.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1668257 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
adrian-crum committed Mar 21, 2015
1 parent 5b972e7 commit fc93556
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
14 changes: 7 additions & 7 deletions framework/entity/src/org/ofbiz/entity/GenericEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1276,14 +1276,14 @@ public void writeXmlText(PrintWriter writer, String prefix) {
*/
@Override
public boolean equals(Object obj) {
if (!(obj instanceof GenericEntity)) return false;

// from here, use the compareTo method since it is more efficient:
try {
return this.compareTo((GenericEntity) obj) == 0;
} catch (ClassCastException e) {
return false;
if (obj == this) {
return true;
}
if (obj instanceof GenericEntity) {
GenericEntity that = (GenericEntity) obj;
return this.entityName.equals(that.entityName) && this.fields.equals(that.fields);
}
return false;
}

/** Creates a hashCode for the entity, using the default String hashCode and Map hashCode, overrides the default hashCode
Expand Down
8 changes: 8 additions & 0 deletions framework/entity/src/org/ofbiz/entity/GenericPK.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public static GenericPK create(GenericPK value) {
return newPK;
}

@Override
public boolean equals(Object obj) {
if (obj instanceof GenericPK) {
return super.equals(obj);
}
return false;
}

/** Clones this GenericPK, this is a shallow clone & uses the default shallow HashMap clone
*@return Object that is a clone of this GenericPK
*/
Expand Down
8 changes: 8 additions & 0 deletions framework/entity/src/org/ofbiz/entity/GenericValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@ public GenericPK getRelatedDummyPK(String relationName, Map<String, ? extends Ob
return this.getDelegator().getRelatedDummyPK(relationName, byAndFields, this);
}

@Override
public boolean equals(Object obj) {
if (obj instanceof GenericValue) {
return super.equals(obj);
}
return false;
}

/** Clones this GenericValue, this is a shallow clone & uses the default shallow HashMap clone
*@return Object that is a clone of this GenericValue
*/
Expand Down

0 comments on commit fc93556

Please sign in to comment.