Skip to content

Commit

Permalink
Merge pull request #27 from software-is-art/equals-identity-short-cir…
Browse files Browse the repository at this point in the history
…cuit

Added Identity Short Circuit to equals methods (Callum Galbreath)
  • Loading branch information
dweiss authored Aug 31, 2021
2 parents 29ab369 + 10e2892 commit dc57e6e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

GH-25: Added addAll(KTypeContainer) on KTypeSet. (Erich Schubert, Dawid Weiss).

GH-27: Added identity short circuit to existing equals methods. (Callum Galbreath).

** Bugs


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,11 +864,12 @@ public int hashCode() {
#end
*/
@Override
public boolean equals(Object obj)
{
return obj != null &&
getClass() == obj.getClass() &&
equalElements(getClass().cast(obj));
public boolean equals(Object obj) {
return (this == obj) || (
obj != null &&
getClass() == obj.getClass() &&
equalElements(getClass().cast(obj))
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,11 @@ public int hashCode() {
*/
@Override
public boolean equals(Object obj) {
return obj != null &&
getClass() == obj.getClass() &&
equalElements(getClass().cast(obj));
return (this == obj) || (
obj != null &&
getClass() == obj.getClass() &&
equalElements(getClass().cast(obj))
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,11 @@ public int hashCode() {
*/
@Override
public boolean equals(Object obj) {
return obj != null &&
getClass() == obj.getClass() &&
sameKeys(getClass().cast(obj));
return (this == obj) || (
obj != null &&
getClass() == obj.getClass() &&
sameKeys(getClass().cast(obj))
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,9 +613,11 @@ public int hashCode() {
*/
@Override
public boolean equals(Object obj) {
return obj != null &&
getClass() == obj.getClass() &&
equalElements(getClass().cast(obj));
return (this == obj) || (
obj != null &&
getClass() == obj.getClass() &&
equalElements(getClass().cast(obj))
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ public void release() {
@Override
@SuppressWarnings("unchecked")
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ public void release() {
@Override
@SuppressWarnings("unchecked")
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Expand Down

0 comments on commit dc57e6e

Please sign in to comment.