Introduce ObjectUtils#nullSafeHash(Object... element)
This commit deprecates the various nullSafeHashCode methods taking array types as they are superseded by Arrays.hashCode now. This means that the now only remaining nullSafeHashCode method does not trigger a warning only if the target type is not an array. At the same time, there are multiple use of this method on several elements, handling the accumulation of hash codes. For that reason, this commit also introduces a nullSafeHash that takes an array of elements. The only difference between Objects.hash is that this method handles arrays. The codebase has been reviewed to use any of those two methods when it is possible. Closes gh-29051
This commit is contained in:
@@ -525,11 +525,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hashCode = ObjectUtils.nullSafeHashCode(getExpression());
|
return ObjectUtils.nullSafeHash(getExpression(), this.pointcutDeclarationScope,
|
||||||
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutDeclarationScope);
|
this.pointcutParameterNames, this.pointcutParameterTypes);
|
||||||
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutParameterNames);
|
|
||||||
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.pointcutParameterTypes);
|
|
||||||
return hashCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.aop.aspectj;
|
package org.springframework.aop.aspectj;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.aspectj.weaver.tools.PointcutParser;
|
import org.aspectj.weaver.tools.PointcutParser;
|
||||||
import org.aspectj.weaver.tools.TypePatternMatcher;
|
import org.aspectj.weaver.tools.TypePatternMatcher;
|
||||||
|
|
||||||
@@ -124,7 +126,7 @@ public class TypePatternClassFilter implements ClassFilter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ObjectUtils.nullSafeHashCode(this.typePattern);
|
return Objects.hashCode(this.typePattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ public abstract class ClassFilters {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ObjectUtils.nullSafeHashCode(this.filters);
|
return Arrays.hashCode(this.filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -170,7 +170,7 @@ public abstract class ClassFilters {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ObjectUtils.nullSafeHashCode(this.filters);
|
return Arrays.hashCode(this.filters);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@@ -190,7 +191,7 @@ public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSour
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getClass().hashCode() * 13 + ObjectUtils.nullSafeHashCode(this.targetBeanName);
|
return Objects.hash(getClass(), this.targetBeanName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.springframework.aop.target;
|
package org.springframework.aop.target;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.springframework.aop.TargetSource;
|
import org.springframework.aop.TargetSource;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
@@ -140,7 +141,7 @@ public final class EmptyTargetSource implements TargetSource, Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return EmptyTargetSource.class.hashCode() * 13 + ObjectUtils.nullSafeHashCode(this.targetClass);
|
return Objects.hash(getClass(), this.targetClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.cache.config;
|
package org.springframework.cache.config;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
@@ -42,7 +44,7 @@ public class TestEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ObjectUtils.nullSafeHashCode(this.id);
|
return Objects.hashCode(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return this.name.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.value);
|
return ObjectUtils.nullSafeHash(this.name, this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import java.lang.reflect.Modifier;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
@@ -345,7 +346,7 @@ class ExtendedBeanInfo implements BeanInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (ObjectUtils.nullSafeHashCode(getReadMethod()) * 29 + ObjectUtils.nullSafeHashCode(getWriteMethod()));
|
return Objects.hash(getReadMethod(), getWriteMethod());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -500,11 +501,8 @@ class ExtendedBeanInfo implements BeanInfo {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hashCode = ObjectUtils.nullSafeHashCode(getReadMethod());
|
return Objects.hash(getReadMethod(), getWriteMethod(),
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(getWriteMethod());
|
getIndexedReadMethod(), getIndexedWriteMethod());
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(getIndexedReadMethod());
|
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(getIndexedWriteMethod());
|
|
||||||
return hashCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import java.beans.IntrospectionException;
|
|||||||
import java.beans.PropertyDescriptor;
|
import java.beans.PropertyDescriptor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@@ -30,7 +31,6 @@ import org.springframework.core.MethodParameter;
|
|||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.ObjectUtils;
|
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -172,10 +172,7 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hashCode = getBeanClass().hashCode();
|
return Objects.hash(getBeanClass(), getReadMethod(), getWriteMethod());
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(getReadMethod());
|
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(getWriteMethod());
|
|
||||||
return hashCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -197,7 +197,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return this.name.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.value);
|
return ObjectUtils.nullSafeHash(this.name, this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,6 +20,7 @@ import java.lang.annotation.Annotation;
|
|||||||
import java.lang.reflect.AnnotatedElement;
|
import java.lang.reflect.AnnotatedElement;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Member;
|
import java.lang.reflect.Member;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
@@ -190,7 +191,7 @@ public class InjectionPoint {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (this.field != null ? this.field.hashCode() : ObjectUtils.nullSafeHashCode(this.methodParameter));
|
return Objects.hash(this.field, this.methodParameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -173,10 +173,8 @@ public class BeanDefinitionHolder implements BeanMetadataElement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hashCode = this.beanDefinition.hashCode();
|
return ObjectUtils.nullSafeHash(this.beanDefinition, this.beanName,
|
||||||
hashCode = 29 * hashCode + this.beanName.hashCode();
|
this.aliases);
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.aliases);
|
|
||||||
return hashCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -606,7 +606,7 @@ public class ConstructorArgumentValues {
|
|||||||
* same content to reside in the same Set.
|
* same content to reside in the same Set.
|
||||||
*/
|
*/
|
||||||
private int contentHashCode() {
|
private int contentHashCode() {
|
||||||
return ObjectUtils.nullSafeHashCode(this.value) * 29 + ObjectUtils.nullSafeHashCode(this.type);
|
return ObjectUtils.nullSafeHash(this.value, this.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ public class TypedStringValue implements BeanMetadataElement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ObjectUtils.nullSafeHashCode(this.value) * 29 + ObjectUtils.nullSafeHashCode(this.targetType);
|
return ObjectUtils.nullSafeHash(this.value, this.targetType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -113,9 +113,7 @@ public abstract class MethodOverride implements BeanMetadataElement {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hashCode = ObjectUtils.nullSafeHashCode(this.methodName);
|
return ObjectUtils.nullSafeHash(this.methodName, this.source);
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.source);
|
|
||||||
return hashCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -236,14 +236,8 @@ public class SimpleMailMessage implements MailMessage, Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hashCode = ObjectUtils.nullSafeHashCode(this.from);
|
return ObjectUtils.nullSafeHash(this.from, this.replyTo, this.to, this.cc,
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.replyTo);
|
this.bcc, this.sentDate, this.subject);
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.to);
|
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.cc);
|
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.bcc);
|
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.sentDate);
|
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.subject);
|
|
||||||
return hashCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.util.Collection;
|
|||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
@@ -404,7 +405,7 @@ public abstract class AbstractApplicationEventMulticaster
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return this.eventType.hashCode() * 29 + ObjectUtils.nullSafeHashCode(this.sourceType);
|
return Objects.hash(this.eventType, this.sourceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.springframework.context.support;
|
package org.springframework.context.support;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
@@ -28,7 +29,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
|
|||||||
import org.springframework.context.ApplicationListener;
|
import org.springframework.context.ApplicationListener;
|
||||||
import org.springframework.context.event.ApplicationEventMulticaster;
|
import org.springframework.context.event.ApplicationEventMulticaster;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.ObjectUtils;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@code BeanPostProcessor} that detects beans which implement the {@code ApplicationListener}
|
* {@code BeanPostProcessor} that detects beans which implement the {@code ApplicationListener}
|
||||||
@@ -120,7 +120,7 @@ class ApplicationListenerDetector implements DestructionAwareBeanPostProcessor,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ObjectUtils.nullSafeHashCode(this.applicationContext);
|
return Objects.hashCode(this.applicationContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,10 +179,7 @@ public class DefaultMessageSourceResolvable implements MessageSourceResolvable,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hashCode = ObjectUtils.nullSafeHashCode(getCodes());
|
return ObjectUtils.nullSafeHash(getCode(), getArguments(), getDefaultMessage());
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(getArguments());
|
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(getDefaultMessage());
|
|
||||||
return hashCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,11 +167,8 @@ public class NotificationListenerHolder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hashCode = ObjectUtils.nullSafeHashCode(this.notificationListener);
|
return ObjectUtils.nullSafeHash(this.notificationListener, this.notificationFilter,
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.notificationFilter);
|
this.handback, this.mappedObjectNames);
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.handback);
|
|
||||||
hashCode = 29 * hashCode + ObjectUtils.nullSafeHashCode(this.mappedObjectNames);
|
|
||||||
return hashCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.context.testfixture.cache.beans;
|
package org.springframework.context.testfixture.cache.beans;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
@@ -38,7 +40,7 @@ public class TestEntity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ObjectUtils.nullSafeHashCode(this.id);
|
return Objects.hashCode(this.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import java.lang.annotation.Annotation;
|
|||||||
import java.lang.annotation.Repeatable;
|
import java.lang.annotation.Repeatable;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
@@ -91,7 +92,7 @@ public abstract class RepeatableContainers {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ObjectUtils.nullSafeHashCode(this.parent);
|
return Objects.hashCode(this.parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.lang.reflect.Field;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.springframework.core.MethodParameter;
|
import org.springframework.core.MethodParameter;
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
@@ -269,7 +270,7 @@ public final class Property {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (ObjectUtils.nullSafeHashCode(this.objectType) * 31 + ObjectUtils.nullSafeHashCode(this.name));
|
return Objects.hash(this.objectType, this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.core.env;
|
package org.springframework.core.env;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
@@ -147,7 +149,7 @@ public abstract class PropertySource<T> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ObjectUtils.nullSafeHashCode(getName());
|
return Objects.hashCode(getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.time.ZoneId;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
@@ -390,21 +391,32 @@ public abstract class ObjectUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return as hash code for the given object; typically the value of
|
* Return a hash code for the given elements, delegating to
|
||||||
|
* {@link #nullSafeHashCode(Object)} for each element. Contrary
|
||||||
|
* to {@link Objects#hash(Object...)}, this method handle an
|
||||||
|
* element that is an array.
|
||||||
|
* @param elements the elements to be hashed
|
||||||
|
* @return a hash value of the elements
|
||||||
|
* @since 6.1
|
||||||
|
*/
|
||||||
|
public static int nullSafeHash(@Nullable Object... elements) {
|
||||||
|
if (elements == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
int result = 1;
|
||||||
|
for (Object element : elements) {
|
||||||
|
result = 31 * result + nullSafeHashCode(element);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a hash code for the given object; typically the value of
|
||||||
* {@code Object#hashCode()}}. If the object is an array,
|
* {@code Object#hashCode()}}. If the object is an array,
|
||||||
* this method will delegate to any of the {@code nullSafeHashCode}
|
* this method will delegate to any of the {@code Arrays#hasCode}
|
||||||
* methods for arrays in this class. If the object is {@code null},
|
* methods. If the object is {@code null}, this method returns 0.
|
||||||
* this method returns 0.
|
|
||||||
* @see Object#hashCode()
|
* @see Object#hashCode()
|
||||||
* @see #nullSafeHashCode(Object[])
|
* @see Arrays
|
||||||
* @see #nullSafeHashCode(boolean[])
|
|
||||||
* @see #nullSafeHashCode(byte[])
|
|
||||||
* @see #nullSafeHashCode(char[])
|
|
||||||
* @see #nullSafeHashCode(double[])
|
|
||||||
* @see #nullSafeHashCode(float[])
|
|
||||||
* @see #nullSafeHashCode(int[])
|
|
||||||
* @see #nullSafeHashCode(long[])
|
|
||||||
* @see #nullSafeHashCode(short[])
|
|
||||||
*/
|
*/
|
||||||
public static int nullSafeHashCode(@Nullable Object obj) {
|
public static int nullSafeHashCode(@Nullable Object obj) {
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
@@ -412,31 +424,31 @@ public abstract class ObjectUtils {
|
|||||||
}
|
}
|
||||||
if (obj.getClass().isArray()) {
|
if (obj.getClass().isArray()) {
|
||||||
if (obj instanceof Object[] objects) {
|
if (obj instanceof Object[] objects) {
|
||||||
return nullSafeHashCode(objects);
|
return Arrays.hashCode(objects);
|
||||||
}
|
}
|
||||||
if (obj instanceof boolean[] booleans) {
|
if (obj instanceof boolean[] booleans) {
|
||||||
return nullSafeHashCode(booleans);
|
return Arrays.hashCode(booleans);
|
||||||
}
|
}
|
||||||
if (obj instanceof byte[] bytes) {
|
if (obj instanceof byte[] bytes) {
|
||||||
return nullSafeHashCode(bytes);
|
return Arrays.hashCode(bytes);
|
||||||
}
|
}
|
||||||
if (obj instanceof char[] chars) {
|
if (obj instanceof char[] chars) {
|
||||||
return nullSafeHashCode(chars);
|
return Arrays.hashCode(chars);
|
||||||
}
|
}
|
||||||
if (obj instanceof double[] doubles) {
|
if (obj instanceof double[] doubles) {
|
||||||
return nullSafeHashCode(doubles);
|
return Arrays.hashCode(doubles);
|
||||||
}
|
}
|
||||||
if (obj instanceof float[] floats) {
|
if (obj instanceof float[] floats) {
|
||||||
return nullSafeHashCode(floats);
|
return Arrays.hashCode(floats);
|
||||||
}
|
}
|
||||||
if (obj instanceof int[] ints) {
|
if (obj instanceof int[] ints) {
|
||||||
return nullSafeHashCode(ints);
|
return Arrays.hashCode(ints);
|
||||||
}
|
}
|
||||||
if (obj instanceof long[] longs) {
|
if (obj instanceof long[] longs) {
|
||||||
return nullSafeHashCode(longs);
|
return Arrays.hashCode(longs);
|
||||||
}
|
}
|
||||||
if (obj instanceof short[] shorts) {
|
if (obj instanceof short[] shorts) {
|
||||||
return nullSafeHashCode(shorts);
|
return Arrays.hashCode(shorts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return obj.hashCode();
|
return obj.hashCode();
|
||||||
@@ -445,136 +457,91 @@ public abstract class ObjectUtils {
|
|||||||
/**
|
/**
|
||||||
* Return a hash code based on the contents of the specified array.
|
* Return a hash code based on the contents of the specified array.
|
||||||
* If {@code array} is {@code null}, this method returns 0.
|
* If {@code array} is {@code null}, this method returns 0.
|
||||||
|
* @deprecated as of 6.1 in favor of {@link Arrays#hashCode(Object[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "6.1")
|
||||||
public static int nullSafeHashCode(@Nullable Object[] array) {
|
public static int nullSafeHashCode(@Nullable Object[] array) {
|
||||||
if (array == null) {
|
return Arrays.hashCode(array);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int hash = INITIAL_HASH;
|
|
||||||
for (Object element : array) {
|
|
||||||
hash = MULTIPLIER * hash + nullSafeHashCode(element);
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a hash code based on the contents of the specified array.
|
* Return a hash code based on the contents of the specified array.
|
||||||
* If {@code array} is {@code null}, this method returns 0.
|
* If {@code array} is {@code null}, this method returns 0.
|
||||||
|
* @deprecated as of 6.1 in favor of {@link Arrays#hashCode(boolean[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "6.1")
|
||||||
public static int nullSafeHashCode(@Nullable boolean[] array) {
|
public static int nullSafeHashCode(@Nullable boolean[] array) {
|
||||||
if (array == null) {
|
return Arrays.hashCode(array);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int hash = INITIAL_HASH;
|
|
||||||
for (boolean element : array) {
|
|
||||||
hash = MULTIPLIER * hash + Boolean.hashCode(element);
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a hash code based on the contents of the specified array.
|
* Return a hash code based on the contents of the specified array.
|
||||||
* If {@code array} is {@code null}, this method returns 0.
|
* If {@code array} is {@code null}, this method returns 0.
|
||||||
|
* @deprecated as of 6.1 in favor of {@link Arrays#hashCode(byte[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "6.1")
|
||||||
public static int nullSafeHashCode(@Nullable byte[] array) {
|
public static int nullSafeHashCode(@Nullable byte[] array) {
|
||||||
if (array == null) {
|
return Arrays.hashCode(array);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int hash = INITIAL_HASH;
|
|
||||||
for (byte element : array) {
|
|
||||||
hash = MULTIPLIER * hash + element;
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a hash code based on the contents of the specified array.
|
* Return a hash code based on the contents of the specified array.
|
||||||
* If {@code array} is {@code null}, this method returns 0.
|
* If {@code array} is {@code null}, this method returns 0.
|
||||||
|
* @deprecated as of 6.1 in favor of {@link Arrays#hashCode(char[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "6.1")
|
||||||
public static int nullSafeHashCode(@Nullable char[] array) {
|
public static int nullSafeHashCode(@Nullable char[] array) {
|
||||||
if (array == null) {
|
return Arrays.hashCode(array);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int hash = INITIAL_HASH;
|
|
||||||
for (char element : array) {
|
|
||||||
hash = MULTIPLIER * hash + element;
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a hash code based on the contents of the specified array.
|
* Return a hash code based on the contents of the specified array.
|
||||||
* If {@code array} is {@code null}, this method returns 0.
|
* If {@code array} is {@code null}, this method returns 0.
|
||||||
|
* @deprecated as of 6.1 in favor of {@link Arrays#hashCode(double[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "6.1")
|
||||||
public static int nullSafeHashCode(@Nullable double[] array) {
|
public static int nullSafeHashCode(@Nullable double[] array) {
|
||||||
if (array == null) {
|
return Arrays.hashCode(array);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int hash = INITIAL_HASH;
|
|
||||||
for (double element : array) {
|
|
||||||
hash = MULTIPLIER * hash + Double.hashCode(element);
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a hash code based on the contents of the specified array.
|
* Return a hash code based on the contents of the specified array.
|
||||||
* If {@code array} is {@code null}, this method returns 0.
|
* If {@code array} is {@code null}, this method returns 0.
|
||||||
|
* @deprecated as of 6.1 in favor of {@link Arrays#hashCode(float[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "6.1")
|
||||||
public static int nullSafeHashCode(@Nullable float[] array) {
|
public static int nullSafeHashCode(@Nullable float[] array) {
|
||||||
if (array == null) {
|
return Arrays.hashCode(array);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int hash = INITIAL_HASH;
|
|
||||||
for (float element : array) {
|
|
||||||
hash = MULTIPLIER * hash + Float.hashCode(element);
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a hash code based on the contents of the specified array.
|
* Return a hash code based on the contents of the specified array.
|
||||||
* If {@code array} is {@code null}, this method returns 0.
|
* If {@code array} is {@code null}, this method returns 0.
|
||||||
|
* @deprecated as of 6.1 in favor of {@link Arrays#hashCode(int[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "6.1")
|
||||||
public static int nullSafeHashCode(@Nullable int[] array) {
|
public static int nullSafeHashCode(@Nullable int[] array) {
|
||||||
if (array == null) {
|
return Arrays.hashCode(array);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int hash = INITIAL_HASH;
|
|
||||||
for (int element : array) {
|
|
||||||
hash = MULTIPLIER * hash + element;
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a hash code based on the contents of the specified array.
|
* Return a hash code based on the contents of the specified array.
|
||||||
* If {@code array} is {@code null}, this method returns 0.
|
* If {@code array} is {@code null}, this method returns 0.
|
||||||
|
* @deprecated as of 6.1 in favor of {@link Arrays#hashCode(long[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "6.1")
|
||||||
public static int nullSafeHashCode(@Nullable long[] array) {
|
public static int nullSafeHashCode(@Nullable long[] array) {
|
||||||
if (array == null) {
|
return Arrays.hashCode(array);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int hash = INITIAL_HASH;
|
|
||||||
for (long element : array) {
|
|
||||||
hash = MULTIPLIER * hash + Long.hashCode(element);
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a hash code based on the contents of the specified array.
|
* Return a hash code based on the contents of the specified array.
|
||||||
* If {@code array} is {@code null}, this method returns 0.
|
* If {@code array} is {@code null}, this method returns 0.
|
||||||
|
* @deprecated as of 6.1 in favor of {@link Arrays#hashCode(short[])}
|
||||||
*/
|
*/
|
||||||
|
@Deprecated(since = "6.1")
|
||||||
public static int nullSafeHashCode(@Nullable short[] array) {
|
public static int nullSafeHashCode(@Nullable short[] array) {
|
||||||
if (array == null) {
|
return Arrays.hashCode(array);
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int hash = INITIAL_HASH;
|
|
||||||
for (short element : array) {
|
|
||||||
hash = MULTIPLIER * hash + element;
|
|
||||||
}
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ import java.nio.file.Path;
|
|||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Currency;
|
import java.util.Currency;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -38,6 +39,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
@@ -379,119 +381,197 @@ class ObjectUtilsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullSafeHashCodeWithBooleanArray() {
|
void nullSafeHashWithNull() {
|
||||||
int expected = 31 * 7 + Boolean.TRUE.hashCode();
|
assertThat(ObjectUtils.nullSafeHash((Object[]) null)).isEqualTo(0);
|
||||||
expected = 31 * expected + Boolean.FALSE.hashCode();
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void nullSafeHashWithIntermediateNullElements() {
|
||||||
|
assertThat(ObjectUtils.nullSafeHash(3, null, 5)).isEqualTo(Objects.hash(3, null, 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Deprecated
|
||||||
|
void nullSafeHashCodeWithNullBooleanArray() {
|
||||||
|
boolean[] array = null;
|
||||||
|
assertThat(ObjectUtils.nullSafeHashCode(array)).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Deprecated
|
||||||
|
void nullSafeHashCodeWithBooleanArray() {
|
||||||
boolean[] array = {true, false};
|
boolean[] array = {true, false};
|
||||||
int actual = ObjectUtils.nullSafeHashCode(array);
|
int actual = ObjectUtils.nullSafeHashCode(array);
|
||||||
|
assertThat(actual).isEqualTo(Arrays.hashCode(array));
|
||||||
assertThat(actual).isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullSafeHashCodeWithBooleanArrayEqualToNull() {
|
@Deprecated
|
||||||
assertThat(ObjectUtils.nullSafeHashCode((boolean[]) null)).isEqualTo(0);
|
void nullSafeHashCodeWithObjectBeingBooleanArray() {
|
||||||
|
Object array = new boolean[] {true, false};
|
||||||
|
int expected = ObjectUtils.nullSafeHashCode((boolean[]) array);
|
||||||
|
assertEqualHashCodes(expected, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Deprecated
|
||||||
|
void nullSafeHashCodeWithNullByteArray() {
|
||||||
|
byte[] array = null;
|
||||||
|
assertThat(ObjectUtils.nullSafeHashCode(array)).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Deprecated
|
||||||
void nullSafeHashCodeWithByteArray() {
|
void nullSafeHashCodeWithByteArray() {
|
||||||
int expected = 31 * 7 + 8;
|
|
||||||
expected = 31 * expected + 10;
|
|
||||||
|
|
||||||
byte[] array = {8, 10};
|
byte[] array = {8, 10};
|
||||||
int actual = ObjectUtils.nullSafeHashCode(array);
|
int actual = ObjectUtils.nullSafeHashCode(array);
|
||||||
|
assertThat(actual).isEqualTo(Arrays.hashCode(array));
|
||||||
assertThat(actual).isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullSafeHashCodeWithByteArrayEqualToNull() {
|
@Deprecated
|
||||||
assertThat(ObjectUtils.nullSafeHashCode((byte[]) null)).isEqualTo(0);
|
void nullSafeHashCodeWithObjectBeingByteArray() {
|
||||||
|
Object array = new byte[] {6, 39};
|
||||||
|
int expected = ObjectUtils.nullSafeHashCode((byte[]) array);
|
||||||
|
assertEqualHashCodes(expected, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Deprecated
|
||||||
|
void nullSafeHashCodeWithNullCharArray() {
|
||||||
|
char[] array = null;
|
||||||
|
assertThat(ObjectUtils.nullSafeHashCode(array)).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Deprecated
|
||||||
void nullSafeHashCodeWithCharArray() {
|
void nullSafeHashCodeWithCharArray() {
|
||||||
int expected = 31 * 7 + 'a';
|
|
||||||
expected = 31 * expected + 'E';
|
|
||||||
|
|
||||||
char[] array = {'a', 'E'};
|
char[] array = {'a', 'E'};
|
||||||
int actual = ObjectUtils.nullSafeHashCode(array);
|
int actual = ObjectUtils.nullSafeHashCode(array);
|
||||||
|
assertThat(actual).isEqualTo(Arrays.hashCode(array));
|
||||||
assertThat(actual).isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullSafeHashCodeWithCharArrayEqualToNull() {
|
@Deprecated
|
||||||
assertThat(ObjectUtils.nullSafeHashCode((char[]) null)).isEqualTo(0);
|
void nullSafeHashCodeWithObjectBeingCharArray() {
|
||||||
|
Object array = new char[] {'l', 'M'};
|
||||||
|
int expected = ObjectUtils.nullSafeHashCode((char[]) array);
|
||||||
|
assertEqualHashCodes(expected, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Deprecated
|
||||||
|
void nullSafeHashCodeWithNullDoubleArray() {
|
||||||
|
double[] array = null;
|
||||||
|
assertThat(ObjectUtils.nullSafeHashCode(array)).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Deprecated
|
||||||
void nullSafeHashCodeWithDoubleArray() {
|
void nullSafeHashCodeWithDoubleArray() {
|
||||||
long bits = Double.doubleToLongBits(8449.65);
|
|
||||||
int expected = 31 * 7 + (int) (bits ^ (bits >>> 32));
|
|
||||||
bits = Double.doubleToLongBits(9944.923);
|
|
||||||
expected = 31 * expected + (int) (bits ^ (bits >>> 32));
|
|
||||||
|
|
||||||
double[] array = {8449.65, 9944.923};
|
double[] array = {8449.65, 9944.923};
|
||||||
int actual = ObjectUtils.nullSafeHashCode(array);
|
int actual = ObjectUtils.nullSafeHashCode(array);
|
||||||
|
assertThat(actual).isEqualTo(Arrays.hashCode(array));
|
||||||
assertThat(actual).isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullSafeHashCodeWithDoubleArrayEqualToNull() {
|
@Deprecated
|
||||||
assertThat(ObjectUtils.nullSafeHashCode((double[]) null)).isEqualTo(0);
|
void nullSafeHashCodeWithObjectBeingDoubleArray() {
|
||||||
|
Object array = new double[] {68930.993, 9022.009};
|
||||||
|
int expected = ObjectUtils.nullSafeHashCode((double[]) array);
|
||||||
|
assertEqualHashCodes(expected, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Deprecated
|
||||||
|
void nullSafeHashCodeWithNullFloatArray() {
|
||||||
|
float[] array = null;
|
||||||
|
assertThat(ObjectUtils.nullSafeHashCode(array)).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Deprecated
|
||||||
void nullSafeHashCodeWithFloatArray() {
|
void nullSafeHashCodeWithFloatArray() {
|
||||||
int expected = 31 * 7 + Float.floatToIntBits(9.6f);
|
|
||||||
expected = 31 * expected + Float.floatToIntBits(7.4f);
|
|
||||||
|
|
||||||
float[] array = {9.6f, 7.4f};
|
float[] array = {9.6f, 7.4f};
|
||||||
int actual = ObjectUtils.nullSafeHashCode(array);
|
int actual = ObjectUtils.nullSafeHashCode(array);
|
||||||
|
assertThat(actual).isEqualTo(Arrays.hashCode(array));
|
||||||
assertThat(actual).isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullSafeHashCodeWithFloatArrayEqualToNull() {
|
@Deprecated
|
||||||
assertThat(ObjectUtils.nullSafeHashCode((float[]) null)).isEqualTo(0);
|
void nullSafeHashCodeWithObjectBeingFloatArray() {
|
||||||
|
Object array = new float[] {9.9f, 9.54f};
|
||||||
|
int expected = ObjectUtils.nullSafeHashCode((float[]) array);
|
||||||
|
assertEqualHashCodes(expected, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Deprecated
|
||||||
|
void nullSafeHashCodeWithNullIntArray() {
|
||||||
|
int[] array = null;
|
||||||
|
assertThat(ObjectUtils.nullSafeHashCode(array)).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Deprecated
|
||||||
void nullSafeHashCodeWithIntArray() {
|
void nullSafeHashCodeWithIntArray() {
|
||||||
int expected = 31 * 7 + 884;
|
|
||||||
expected = 31 * expected + 340;
|
|
||||||
|
|
||||||
int[] array = {884, 340};
|
int[] array = {884, 340};
|
||||||
int actual = ObjectUtils.nullSafeHashCode(array);
|
int actual = ObjectUtils.nullSafeHashCode(array);
|
||||||
|
assertThat(actual).isEqualTo(Arrays.hashCode(array));
|
||||||
assertThat(actual).isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullSafeHashCodeWithIntArrayEqualToNull() {
|
@Deprecated
|
||||||
assertThat(ObjectUtils.nullSafeHashCode((int[]) null)).isEqualTo(0);
|
void nullSafeHashCodeWithObjectBeingIntArray() {
|
||||||
|
Object array = new int[] {89, 32};
|
||||||
|
int expected = ObjectUtils.nullSafeHashCode((int[]) array);
|
||||||
|
assertEqualHashCodes(expected, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Deprecated
|
||||||
|
void nullSafeHashCodeWithNullLongArray() {
|
||||||
|
long[] array = null;
|
||||||
|
assertThat(ObjectUtils.nullSafeHashCode(array)).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Deprecated
|
||||||
void nullSafeHashCodeWithLongArray() {
|
void nullSafeHashCodeWithLongArray() {
|
||||||
long lng = 7993L;
|
|
||||||
int expected = 31 * 7 + (int) (lng ^ (lng >>> 32));
|
|
||||||
lng = 84320L;
|
|
||||||
expected = 31 * expected + (int) (lng ^ (lng >>> 32));
|
|
||||||
|
|
||||||
long[] array = {7993L, 84320L};
|
long[] array = {7993L, 84320L};
|
||||||
int actual = ObjectUtils.nullSafeHashCode(array);
|
int actual = ObjectUtils.nullSafeHashCode(array);
|
||||||
|
assertThat(actual).isEqualTo(Arrays.hashCode(array));
|
||||||
assertThat(actual).isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullSafeHashCodeWithLongArrayEqualToNull() {
|
@Deprecated
|
||||||
assertThat(ObjectUtils.nullSafeHashCode((long[]) null)).isEqualTo(0);
|
void nullSafeHashCodeWithObjectBeingLongArray() {
|
||||||
|
Object array = new long[] {4389, 320};
|
||||||
|
int expected = ObjectUtils.nullSafeHashCode((long[]) array);
|
||||||
|
assertEqualHashCodes(expected, array);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Deprecated
|
||||||
|
void nullSafeHashCodeWithNullShortArray() {
|
||||||
|
short[] array = null;
|
||||||
|
assertThat(ObjectUtils.nullSafeHashCode(array)).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Deprecated
|
||||||
|
void nullSafeHashCodeWithShortArray() {
|
||||||
|
short[] array = {4, 25};
|
||||||
|
int actual = ObjectUtils.nullSafeHashCode(array);
|
||||||
|
assertThat(actual).isEqualTo(Arrays.hashCode(array));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Deprecated
|
||||||
|
void nullSafeHashCodeWithObjectBeingShortArray() {
|
||||||
|
Object array = new short[] {5, 3};
|
||||||
|
int expected = ObjectUtils.nullSafeHashCode((short[]) array);
|
||||||
|
assertEqualHashCodes(expected, array);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -501,71 +581,21 @@ class ObjectUtilsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Deprecated
|
||||||
void nullSafeHashCodeWithObjectArray() {
|
void nullSafeHashCodeWithObjectArray() {
|
||||||
int expected = 31 * 7 + "Leia".hashCode();
|
|
||||||
expected = 31 * expected + "Han".hashCode();
|
|
||||||
|
|
||||||
Object[] array = {"Leia", "Han"};
|
Object[] array = {"Leia", "Han"};
|
||||||
int actual = ObjectUtils.nullSafeHashCode(array);
|
int actual = ObjectUtils.nullSafeHashCode(array);
|
||||||
|
assertThat(actual).isEqualTo(Arrays.hashCode(array));
|
||||||
assertThat(actual).isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@Deprecated
|
||||||
void nullSafeHashCodeWithObjectArrayEqualToNull() {
|
void nullSafeHashCodeWithObjectArrayEqualToNull() {
|
||||||
assertThat(ObjectUtils.nullSafeHashCode((Object[]) null)).isEqualTo(0);
|
assertThat(ObjectUtils.nullSafeHashCode((Object[]) null)).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullSafeHashCodeWithObjectBeingBooleanArray() {
|
@Deprecated
|
||||||
Object array = new boolean[] {true, false};
|
|
||||||
int expected = ObjectUtils.nullSafeHashCode((boolean[]) array);
|
|
||||||
assertEqualHashCodes(expected, array);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void nullSafeHashCodeWithObjectBeingByteArray() {
|
|
||||||
Object array = new byte[] {6, 39};
|
|
||||||
int expected = ObjectUtils.nullSafeHashCode((byte[]) array);
|
|
||||||
assertEqualHashCodes(expected, array);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void nullSafeHashCodeWithObjectBeingCharArray() {
|
|
||||||
Object array = new char[] {'l', 'M'};
|
|
||||||
int expected = ObjectUtils.nullSafeHashCode((char[]) array);
|
|
||||||
assertEqualHashCodes(expected, array);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void nullSafeHashCodeWithObjectBeingDoubleArray() {
|
|
||||||
Object array = new double[] {68930.993, 9022.009};
|
|
||||||
int expected = ObjectUtils.nullSafeHashCode((double[]) array);
|
|
||||||
assertEqualHashCodes(expected, array);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void nullSafeHashCodeWithObjectBeingFloatArray() {
|
|
||||||
Object array = new float[] {9.9f, 9.54f};
|
|
||||||
int expected = ObjectUtils.nullSafeHashCode((float[]) array);
|
|
||||||
assertEqualHashCodes(expected, array);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void nullSafeHashCodeWithObjectBeingIntArray() {
|
|
||||||
Object array = new int[] {89, 32};
|
|
||||||
int expected = ObjectUtils.nullSafeHashCode((int[]) array);
|
|
||||||
assertEqualHashCodes(expected, array);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void nullSafeHashCodeWithObjectBeingLongArray() {
|
|
||||||
Object array = new long[] {4389, 320};
|
|
||||||
int expected = ObjectUtils.nullSafeHashCode((long[]) array);
|
|
||||||
assertEqualHashCodes(expected, array);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void nullSafeHashCodeWithObjectBeingObjectArray() {
|
void nullSafeHashCodeWithObjectBeingObjectArray() {
|
||||||
Object array = new Object[] {"Luke", "Anakin"};
|
Object array = new Object[] {"Luke", "Anakin"};
|
||||||
int expected = ObjectUtils.nullSafeHashCode((Object[]) array);
|
int expected = ObjectUtils.nullSafeHashCode((Object[]) array);
|
||||||
@@ -573,31 +603,10 @@ class ObjectUtilsTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nullSafeHashCodeWithObjectBeingShortArray() {
|
@Deprecated
|
||||||
Object array = new short[] {5, 3};
|
|
||||||
int expected = ObjectUtils.nullSafeHashCode((short[]) array);
|
|
||||||
assertEqualHashCodes(expected, array);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void nullSafeHashCodeWithObjectEqualToNull() {
|
void nullSafeHashCodeWithObjectEqualToNull() {
|
||||||
assertThat(ObjectUtils.nullSafeHashCode((Object) null)).isEqualTo(0);
|
Object[] array = null;
|
||||||
}
|
assertThat(ObjectUtils.nullSafeHashCode(array)).isEqualTo(0);
|
||||||
|
|
||||||
@Test
|
|
||||||
void nullSafeHashCodeWithShortArray() {
|
|
||||||
int expected = 31 * 7 + 70;
|
|
||||||
expected = 31 * expected + 8;
|
|
||||||
|
|
||||||
short[] array = {70, 8};
|
|
||||||
int actual = ObjectUtils.nullSafeHashCode(array);
|
|
||||||
|
|
||||||
assertThat(actual).isEqualTo(expected);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void nullSafeHashCodeWithShortArrayEqualToNull() {
|
|
||||||
assertThat(ObjectUtils.nullSafeHashCode((short[]) null)).isEqualTo(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import java.util.Collections;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
@@ -539,7 +540,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return getId().hashCode() * 31 + ObjectUtils.nullSafeHashCode(getSession());
|
return Objects.hash(getId(), getSession());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public class GenericMessage<T> implements Message<T>, Serializable {
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
// Using nullSafeHashCode for proper array hashCode handling
|
// Using nullSafeHashCode for proper array hashCode handling
|
||||||
return ObjectUtils.nullSafeHashCode(this.payload) * 23 + this.headers.hashCode();
|
return ObjectUtils.nullSafeHash(this.payload, this.headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.messaging.simp.user;
|
package org.springframework.messaging.simp.user;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
|
|
||||||
@@ -66,7 +68,7 @@ public class TestSimpSubscription implements SimpSubscription {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return this.id.hashCode() * 31 + ObjectUtils.nullSafeHashCode(getSession());
|
return Objects.hash(this.id, getSession());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public final class Parameter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return ObjectUtils.nullSafeHashCode(this.value) + ObjectUtils.nullSafeHashCode(this.type);
|
return ObjectUtils.nullSafeHash(this.value, this.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -240,15 +240,8 @@ public final class ContentDisposition {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = ObjectUtils.nullSafeHashCode(this.type);
|
return ObjectUtils.nullSafeHash(this.type, this.name,this.filename,
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.name);
|
this.charset, this.size, this.creationDate, this.modificationDate, this.readDate);
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.filename);
|
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.charset);
|
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.size);
|
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.creationDate);
|
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.modificationDate);
|
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.readDate);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -141,7 +141,7 @@ public class HttpEntity<T> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (ObjectUtils.nullSafeHashCode(this.headers) * 29 + ObjectUtils.nullSafeHashCode(this.body));
|
return ObjectUtils.nullSafeHash(this.headers, this.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
|
|
||||||
import org.springframework.core.io.InputStreamResource;
|
import org.springframework.core.io.InputStreamResource;
|
||||||
@@ -276,8 +277,7 @@ public abstract class HttpRange {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (ObjectUtils.nullSafeHashCode(this.firstPos) * 31 +
|
return Objects.hash(this.firstPos, this.lastPos);
|
||||||
ObjectUtils.nullSafeHashCode(this.lastPos));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ package org.springframework.http;
|
|||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
@@ -244,13 +245,8 @@ public class ProblemDetail {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = this.type.hashCode();
|
return Objects.hash(this.type, getTitle(), this.status, this.detail,
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(getTitle());
|
this.instance, this.properties);
|
||||||
result = 31 * result + this.status;
|
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.detail);
|
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.instance);
|
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.properties);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import java.nio.charset.Charset;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
@@ -566,14 +567,8 @@ final class HierarchicalUriComponents extends UriComponents {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = ObjectUtils.nullSafeHashCode(getScheme());
|
return Objects.hash(getScheme(), this.userInfo, this.host, this.port,
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.userInfo);
|
this.path, this.queryParams, getFragment());
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.host);
|
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.port);
|
|
||||||
result = 31 * result + this.path.hashCode();
|
|
||||||
result = 31 * result + this.queryParams.hashCode();
|
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(getFragment());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import java.net.URISyntaxException;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
@@ -166,10 +167,7 @@ final class OpaqueUriComponents extends UriComponents {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = ObjectUtils.nullSafeHashCode(getScheme());
|
return Objects.hash(getScheme(), this.ssp, getFragment());
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.ssp);
|
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(getFragment());
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package org.springframework.web.reactive.socket;
|
package org.springframework.web.reactive.socket;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.ObjectUtils;
|
import org.springframework.util.ObjectUtils;
|
||||||
@@ -231,7 +233,7 @@ public final class CloseStatus {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return this.code * 29 + ObjectUtils.nullSafeHashCode(this.reason);
|
return Objects.hash(this.code, this.reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.springframework.web.socket;
|
package org.springframework.web.socket;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
@@ -213,7 +214,7 @@ public final class CloseStatus implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return this.code * 29 + ObjectUtils.nullSafeHashCode(this.reason);
|
return Objects.hash(this.code, this.reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user