1
0
mirror of synced 2026-08-05 17:57:15 +00:00

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
@@ -46,32 +46,28 @@ public class RequestKey {
return this.method;
}
@Override
public int hashCode() {
int result = this.url.hashCode();
result = 31 * result + (this.method != null ? this.method.hashCode() : 0);
return result;
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof RequestKey)) {
return false;
}
RequestKey key = (RequestKey) obj;
if (!this.url.equals(key.url)) {
return false;
}
if (this.method == null) {
return key.method == null;
}
return this.method.equals(key.method);
}
@Override
public int hashCode() {
int result = this.url.hashCode();
result = 31 * result + (this.method != null ? this.method.hashCode() : 0);
return result;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(this.url.length() + 7);
@@ -59,27 +59,25 @@ public final class SwitchUserGrantedAuthority implements GrantedAuthority {
return this.role;
}
@Override
public int hashCode() {
int result = this.role.hashCode();
result = 31 * result + this.source.hashCode();
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof SwitchUserGrantedAuthority) {
SwitchUserGrantedAuthority swa = (SwitchUserGrantedAuthority) obj;
return this.role.equals(swa.role) && this.source.equals(swa.source);
}
return false;
}
@Override
public int hashCode() {
int result = this.role.hashCode();
result = 31 * result + this.source.hashCode();
return result;
}
@Override
public String toString() {
return "Switch User Authority [" + this.role + "," + this.source + "]";
@@ -129,28 +129,12 @@ public final class LazyCsrfTokenRepository implements CsrfTokenRepository {
return this.delegate.getToken();
}
@Override
public String toString() {
return "SaveOnAccessCsrfToken [delegate=" + this.delegate + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.delegate == null) ? 0 : this.delegate.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
SaveOnAccessCsrfToken other = (SaveOnAccessCsrfToken) obj;
@@ -165,6 +149,19 @@ public final class LazyCsrfTokenRepository implements CsrfTokenRepository {
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.delegate == null) ? 0 : this.delegate.hashCode());
return result;
}
@Override
public String toString() {
return "SaveOnAccessCsrfToken [delegate=" + this.delegate + "]";
}
private void saveTokenIfNecessary() {
if (this.tokenRepository == null) {
return;
@@ -283,13 +283,13 @@ public abstract class OnCommittedResponseWrapper extends HttpServletResponseWrap
}
@Override
public int hashCode() {
return this.delegate.hashCode();
public boolean equals(Object obj) {
return this.delegate.equals(obj);
}
@Override
public boolean equals(Object obj) {
return this.delegate.equals(obj);
public int hashCode() {
return this.delegate.hashCode();
}
@Override
@@ -529,16 +529,6 @@ public abstract class OnCommittedResponseWrapper extends HttpServletResponseWrap
this.delegate.close();
}
@Override
public int hashCode() {
return this.delegate.hashCode();
}
@Override
public boolean equals(Object obj) {
return this.delegate.equals(obj);
}
@Override
public void print(boolean b) throws IOException {
trackContentLength(b);
@@ -658,6 +648,16 @@ public abstract class OnCommittedResponseWrapper extends HttpServletResponseWrap
this.delegate.setWriteListener(writeListener);
}
@Override
public boolean equals(Object obj) {
return this.delegate.equals(obj);
}
@Override
public int hashCode() {
return this.delegate.hashCode();
}
@Override
public String toString() {
return getClass().getName() + "[delegate=" + this.delegate.toString() + "]";
@@ -279,14 +279,6 @@ public class AuthenticationPrincipalArgumentResolverTests {
this.property = toCopy.property;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.property == null) ? 0 : this.property.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
@@ -310,6 +302,14 @@ public class AuthenticationPrincipalArgumentResolverTests {
return true;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.property == null) ? 0 : this.property.hashCode());
return result;
}
}
}