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

@@ -853,14 +853,9 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CacheOperationCacheKey otherKey)) {
return false;
}
return (this.cacheOperation.equals(otherKey.cacheOperation) &&
this.methodCacheKey.equals(otherKey.methodCacheKey));
return (this == other || (other instanceof CacheOperationCacheKey that &&
this.cacheOperation.equals(that.cacheOperation) &&
this.methodCacheKey.equals(that.methodCacheKey)));
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 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.
@@ -65,7 +65,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex
* through {@link #register} calls and then manually {@linkplain #refresh refreshed}.
*/
public AnnotationConfigApplicationContext() {
StartupStep createAnnotatedBeanDefReader = this.getApplicationStartup().start("spring.context.annotated-bean-reader.create");
StartupStep createAnnotatedBeanDefReader = getApplicationStartup().start("spring.context.annotated-bean-reader.create");
this.reader = new AnnotatedBeanDefinitionReader(this);
createAnnotatedBeanDefReader.end();
this.scanner = new ClassPathBeanDefinitionScanner(this);
@@ -163,7 +163,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex
@Override
public void register(Class<?>... componentClasses) {
Assert.notEmpty(componentClasses, "At least one component class must be specified");
StartupStep registerComponentClass = this.getApplicationStartup().start("spring.context.component-classes.register")
StartupStep registerComponentClass = getApplicationStartup().start("spring.context.component-classes.register")
.tag("classes", () -> Arrays.toString(componentClasses));
this.reader.register(componentClasses);
registerComponentClass.end();
@@ -180,7 +180,7 @@ public class AnnotationConfigApplicationContext extends GenericApplicationContex
@Override
public void scan(String... basePackages) {
Assert.notEmpty(basePackages, "At least one base package must be specified");
StartupStep scanPackages = this.getApplicationStartup().start("spring.context.base-packages.scan")
StartupStep scanPackages = getApplicationStartup().start("spring.context.base-packages.scan")
.tag("packages", () -> Arrays.toString(basePackages));
this.scanner.scan(basePackages);
scanPackages.end();

View File

@@ -397,14 +397,9 @@ public abstract class AbstractApplicationEventMulticaster
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ListenerCacheKey otherKey)) {
return false;
}
return (this.eventType.equals(otherKey.eventType) &&
ObjectUtils.nullSafeEquals(this.sourceType, otherKey.sourceType));
return (this == other || (other instanceof ListenerCacheKey that &&
this.eventType.equals(that.eventType) &&
ObjectUtils.nullSafeEquals(this.sourceType, that.sourceType)));
}
@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.
@@ -52,14 +52,9 @@ public final class AnnotatedElementKey implements Comparable<AnnotatedElementKey
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof AnnotatedElementKey otherKey)) {
return false;
}
return (this.element.equals(otherKey.element) &&
ObjectUtils.nullSafeEquals(this.targetClass, otherKey.targetClass));
return (this == other || (other instanceof AnnotatedElementKey that &&
this.element.equals(that.element) &&
ObjectUtils.nullSafeEquals(this.targetClass, that.targetClass)));
}
@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.
@@ -124,14 +124,9 @@ public abstract class CachedExpressionEvaluator {
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof ExpressionKey otherKey)) {
return false;
}
return (this.element.equals(otherKey.element) &&
ObjectUtils.nullSafeEquals(this.expression, otherKey.expression));
return (this == other || (other instanceof ExpressionKey that &&
this.element.equals(that.element) &&
ObjectUtils.nullSafeEquals(this.expression, that.expression)));
}
@Override

View File

@@ -84,7 +84,7 @@ public abstract class AbstractXmlApplicationContext extends AbstractRefreshableC
// Configure the bean definition reader with this context's
// resource loading environment.
beanDefinitionReader.setEnvironment(this.getEnvironment());
beanDefinitionReader.setEnvironment(getEnvironment());
beanDefinitionReader.setResourceLoader(this);
beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));

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.
@@ -171,15 +171,10 @@ public class DefaultMessageSourceResolvable implements MessageSourceResolvable,
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof MessageSourceResolvable otherResolvable)) {
return false;
}
return (ObjectUtils.nullSafeEquals(getCodes(), otherResolvable.getCodes()) &&
ObjectUtils.nullSafeEquals(getArguments(), otherResolvable.getArguments()) &&
ObjectUtils.nullSafeEquals(getDefaultMessage(), otherResolvable.getDefaultMessage()));
return (this == other || (other instanceof MessageSourceResolvable that &&
ObjectUtils.nullSafeEquals(getCodes(), that.getCodes()) &&
ObjectUtils.nullSafeEquals(getArguments(), that.getArguments()) &&
ObjectUtils.nullSafeEquals(getDefaultMessage(), that.getDefaultMessage())));
}
@Override

View File

@@ -367,13 +367,8 @@ public class FormattingConversionService extends GenericConversionService
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof AnnotationConverterKey otherKey)) {
return false;
}
return (this.fieldType == otherKey.fieldType && this.annotation.equals(otherKey.annotation));
return (this == other || (other instanceof AnnotationConverterKey that &&
this.fieldType == that.fieldType && this.annotation.equals(that.annotation)));
}
@Override

View File

@@ -655,13 +655,9 @@ public class MBeanClientInterceptor
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof MethodCacheKey otherKey)) {
return false;
}
return (this.name.equals(otherKey.name) && Arrays.equals(this.parameterTypes, otherKey.parameterTypes));
return (this == other || (other instanceof MethodCacheKey that &&
this.name.equals(that.name) &&
Arrays.equals(this.parameterTypes, that.parameterTypes)));
}
@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.
@@ -158,16 +158,11 @@ public class NotificationListenerHolder {
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof NotificationListenerHolder otherNlh)) {
return false;
}
return (ObjectUtils.nullSafeEquals(this.notificationListener, otherNlh.notificationListener) &&
ObjectUtils.nullSafeEquals(this.notificationFilter, otherNlh.notificationFilter) &&
ObjectUtils.nullSafeEquals(this.handback, otherNlh.handback) &&
ObjectUtils.nullSafeEquals(this.mappedObjectNames, otherNlh.mappedObjectNames));
return (this == other || (other instanceof NotificationListenerHolder that &&
ObjectUtils.nullSafeEquals(this.notificationListener, that.notificationListener) &&
ObjectUtils.nullSafeEquals(this.notificationFilter, that.notificationFilter) &&
ObjectUtils.nullSafeEquals(this.handback, that.handback) &&
ObjectUtils.nullSafeEquals(this.mappedObjectNames, that.mappedObjectNames)));
}
@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.
@@ -435,15 +435,10 @@ public class CronSequenceGenerator {
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof CronSequenceGenerator otherCron)) {
return false;
}
return (this.months.equals(otherCron.months) && this.daysOfMonth.equals(otherCron.daysOfMonth) &&
this.daysOfWeek.equals(otherCron.daysOfWeek) && this.hours.equals(otherCron.hours) &&
this.minutes.equals(otherCron.minutes) && this.seconds.equals(otherCron.seconds));
return (this == other || (other instanceof CronSequenceGenerator that &&
this.months.equals(that.months) && this.daysOfMonth.equals(that.daysOfMonth) &&
this.daysOfWeek.equals(that.daysOfWeek) && this.hours.equals(that.hours) &&
this.minutes.equals(that.minutes) && this.seconds.equals(that.seconds)));
}
@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.
@@ -247,15 +247,10 @@ public class PeriodicTrigger implements Trigger {
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof PeriodicTrigger otherTrigger)) {
return false;
}
return (this.fixedRate == otherTrigger.fixedRate &&
this.period.equals(otherTrigger.period) &&
Objects.equals(this.initialDelay, otherTrigger.initialDelay));
return (this == other || (other instanceof PeriodicTrigger that &&
this.fixedRate == that.fixedRate &&
this.period.equals(that.period) &&
Objects.equals(this.initialDelay, that.initialDelay)));
}
@Override

View File

@@ -358,15 +358,10 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof BindingResult otherResult)) {
return false;
}
return (getObjectName().equals(otherResult.getObjectName()) &&
ObjectUtils.nullSafeEquals(getTarget(), otherResult.getTarget()) &&
getAllErrors().equals(otherResult.getAllErrors()));
return (this == other || (other instanceof BindingResult that &&
getObjectName().equals(that.getObjectName()) &&
ObjectUtils.nullSafeEquals(getTarget(), that.getTarget()) &&
getAllErrors().equals(that.getAllErrors())));
}
@Override