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.
@@ -162,15 +162,10 @@ public final class FlashMap extends HashMap<String, Object> implements Comparabl
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof FlashMap otherFlashMap)) {
return false;
}
return (super.equals(otherFlashMap) &&
ObjectUtils.nullSafeEquals(this.targetRequestPath, otherFlashMap.targetRequestPath) &&
this.targetRequestParams.equals(otherFlashMap.targetRequestParams));
return (this == other || (other instanceof FlashMap that &&
super.equals(other) &&
ObjectUtils.nullSafeEquals(this.targetRequestPath, that.targetRequestPath) &&
this.targetRequestParams.equals(that.targetRequestParams)));
}
@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.
@@ -68,7 +68,7 @@ abstract class AbstractMediaTypeExpression implements MediaTypeExpression, Compa
@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

@@ -475,19 +475,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 (getActivePatternsCondition().equals(otherInfo.getActivePatternsCondition()) &&
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 &&
getActivePatternsCondition().equals(that.getActivePatternsCondition()) &&
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

@@ -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.
@@ -231,13 +231,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.
@@ -234,7 +234,7 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
if (this.renderFunction == null && viewConfig.getRenderFunction() != null) {
this.renderFunction = viewConfig.getRenderFunction();
}
if (this.getContentType() == null) {
if (getContentType() == null) {
setContentType(viewConfig.getContentType() != null ? viewConfig.getContentType() : DEFAULT_CONTENT_TYPE);
}
if (this.charset == null) {
@@ -467,18 +467,14 @@ public class ScriptTemplateView extends AbstractUrlBasedView {
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof EngineKey otherKey)) {
return false;
}
return (this.engineName.equals(otherKey.engineName) && Arrays.equals(this.scripts, otherKey.scripts));
return (this == other || (other instanceof EngineKey that &&
this.engineName.equals(that.engineName) &&
Arrays.equals(this.scripts, that.scripts)));
}
@Override
public int hashCode() {
return (this.engineName.hashCode() * 29 + Arrays.hashCode(this.scripts));
return this.engineName.hashCode() * 29 + Arrays.hashCode(this.scripts);
}
}

View File

@@ -19,6 +19,7 @@ package org.springframework.web.servlet.tags.form;
import java.beans.PropertyEditorSupport;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
* @author Juergen Hoeller
@@ -45,13 +46,8 @@ public class ItemPet {
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ItemPet otherPet)) {
return false;
}
return (this.name != null && this.name.equals(otherPet.getName()));
return (this == other || (other instanceof ItemPet that &&
ObjectUtils.nullSafeEquals(this.name, that.getName())));
}
@Override