Consistent equals/hashCode style (and related polishing)

This commit is contained in:
Juergen Hoeller
2023-07-19 00:35:19 +02:00
parent bbcc788f60
commit 2f33e77ab4
98 changed files with 413 additions and 835 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -167,18 +167,13 @@ public abstract class ExchangeFilterFunctions {
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof Credentials otherCred)) {
return false;
}
return (this.username.equals(otherCred.username) && this.password.equals(otherCred.password));
return (this == other ||(other instanceof Credentials that &&
this.username.equals(that.username) && this.password.equals(that.password)));
}
@Override
public int hashCode() {
return 31 * this.username.hashCode() + this.password.hashCode();
return this.username.hashCode() * 31 + this.password.hashCode();
}
}

View File

@@ -282,13 +282,8 @@ public class CssLinkResourceTransformer extends ResourceTransformerSupport {
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ContentChunkInfo otherCci)) {
return false;
}
return (this.start == otherCci.start && this.end == otherCci.end);
return (this == other || (other instanceof ContentChunkInfo that &&
this.start == that.start && this.end == that.end));
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -95,7 +95,7 @@ abstract class AbstractMediaTypeExpression implements Comparable<AbstractMediaTy
@Override
public int compareTo(AbstractMediaTypeExpression other) {
MediaType mediaType1 = this.getMediaType();
MediaType mediaType1 = getMediaType();
MediaType mediaType2 = other.getMediaType();
if (mediaType1.isMoreSpecific(mediaType2)) {
return -1;

View File

@@ -340,19 +340,14 @@ public final class RequestMappingInfo implements RequestCondition<RequestMapping
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof RequestMappingInfo otherInfo)) {
return false;
}
return (this.patternsCondition.equals(otherInfo.patternsCondition) &&
this.methodsCondition.equals(otherInfo.methodsCondition) &&
this.paramsCondition.equals(otherInfo.paramsCondition) &&
this.headersCondition.equals(otherInfo.headersCondition) &&
this.consumesCondition.equals(otherInfo.consumesCondition) &&
this.producesCondition.equals(otherInfo.producesCondition) &&
this.customConditionHolder.equals(otherInfo.customConditionHolder));
return (this == other || (other instanceof RequestMappingInfo that &&
this.patternsCondition.equals(that.patternsCondition) &&
this.methodsCondition.equals(that.methodsCondition) &&
this.paramsCondition.equals(that.paramsCondition) &&
this.headersCondition.equals(that.headersCondition) &&
this.consumesCondition.equals(that.consumesCondition) &&
this.producesCondition.equals(that.producesCondition) &&
this.customConditionHolder.equals(that.customConditionHolder)));
}
@Override

View File

@@ -224,14 +224,9 @@ public final class CloseStatus {
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CloseStatus otherStatus)) {
return false;
}
return (this.code == otherStatus.code &&
ObjectUtils.nullSafeEquals(this.reason, otherStatus.reason));
return (this == other || (other instanceof CloseStatus that &&
this.code == that.code &&
ObjectUtils.nullSafeEquals(this.reason, that.reason)));
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -157,14 +157,9 @@ public class WebSocketMessage {
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof WebSocketMessage otherMessage)) {
return false;
}
return (this.type.equals(otherMessage.type) &&
ObjectUtils.nullSafeEquals(this.payload, otherMessage.payload));
return (this == other || (other instanceof WebSocketMessage that &&
this.type.equals(that.type) &&
ObjectUtils.nullSafeEquals(this.payload, that.payload)));
}
@Override