Use consistent equals/hashCode/toString order

Ensure that `equals` `hashCode` and `toString` methods always appear in
the same order. This aligns with the style used in Spring Framework.

Issue gh-8945
This commit is contained in:
Phillip Webb
2020-07-29 20:03:19 -07:00
committed by Rob Winch
parent 612fb22a7f
commit ec6a4cb3f0
12 changed files with 95 additions and 111 deletions

View File

@@ -53,27 +53,25 @@ public final class JaasGrantedAuthority implements GrantedAuthority {
return this.role;
}
@Override
public int hashCode() {
int result = this.principal.hashCode();
result = 31 * result + this.role.hashCode();
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof JaasGrantedAuthority) {
JaasGrantedAuthority jga = (JaasGrantedAuthority) obj;
return this.role.equals(jga.role) && this.principal.equals(jga.principal);
}
return false;
}
@Override
public int hashCode() {
int result = this.principal.hashCode();
result = 31 * result + this.role.hashCode();
return result;
}
@Override
public String toString() {
return "Jaas Authority [" + this.role + "," + this.principal + "]";

View File

@@ -62,18 +62,17 @@ public class InMemoryResource extends AbstractResource {
return new ByteArrayInputStream(this.source);
}
@Override
public int hashCode() {
return 1;
}
@Override
public boolean equals(Object res) {
if (!(res instanceof InMemoryResource)) {
return false;
}
return Arrays.equals(this.source, ((InMemoryResource) res).source);
}
@Override
public int hashCode() {
return 1;
}
}