Skip to content

Commit

Permalink
remove equal() override on ebean entity model
Browse files Browse the repository at this point in the history
  • Loading branch information
yangyangv2 committed Jun 6, 2023
1 parent 6273d6e commit 5129349
Showing 1 changed file with 0 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,39 +88,6 @@ public static class PrimaryKey {
@Column(name = CREATED_FOR_COLUMN, nullable = true)
private String createdFor;

@SneakyThrows
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o.getClass() != this.getClass()) {
return false;
}
EbeanMetadataAspect other = (EbeanMetadataAspect) o;

boolean primitiveEqualityCheck = this.key.equals(other.key)
// either both metadata fields are null or both are equal (will check non-null equality after)
&& ((this.metadata == null && other.metadata == null) || (this.metadata != null && other.metadata != null))
&& Math.abs(this.createdOn.getTime() - other.getCreatedOn().getTime()) < 1000 // timestamps are considered equal if within 1s of each other
&& this.createdBy.equals(other.getCreatedBy())
// either both createdFor fields are null or both are equal (need to check this.createdFor != null to avoid NPE)
&& ((this.createdFor == null && other.getCreatedFor() == null) || (this.createdFor != null && this.createdFor.equals(other.getCreatedFor())));
if (!primitiveEqualityCheck) {
return false;
}

JSONParser parser = new JSONParser();
JSONObject thisMetadata = (JSONObject) parser.parse(this.metadata);
JSONObject otherMetadata = (JSONObject) parser.parse(other.metadata);
return thisMetadata.equals(otherMetadata);
}

@Override
public int hashCode() {
return super.hashCode();
}

@Override
public String toString() {
final String str = "EbeanMetadataAspect: {key: <urn:%s, aspect:%s, version:%s>, createdOn: %s, createdBy: %s, createdFor: %s, metadata: %s}";
Expand Down

0 comments on commit 5129349

Please sign in to comment.