Browse Source

Deprecate ObjectUtils.hashCode for primitives in favor of JDK 8's hashCode methods

Issue: SPR-15395
pull/1374/head
Juergen Hoeller 8 years ago
parent
commit
e9627a10c7
  1. 36
      spring-core/src/main/java/org/springframework/util/ObjectUtils.java
  2. 4
      spring-web/src/main/java/org/springframework/http/HttpRange.java

36
spring-core/src/main/java/org/springframework/util/ObjectUtils.java

@ -447,7 +447,7 @@ public abstract class ObjectUtils { @@ -447,7 +447,7 @@ public abstract class ObjectUtils {
}
int hash = INITIAL_HASH;
for (boolean element : array) {
hash = MULTIPLIER * hash + hashCode(element);
hash = MULTIPLIER * hash + Boolean.hashCode(element);
}
return hash;
}
@ -492,7 +492,7 @@ public abstract class ObjectUtils { @@ -492,7 +492,7 @@ public abstract class ObjectUtils {
}
int hash = INITIAL_HASH;
for (double element : array) {
hash = MULTIPLIER * hash + hashCode(element);
hash = MULTIPLIER * hash + Double.hashCode(element);
}
return hash;
}
@ -507,7 +507,7 @@ public abstract class ObjectUtils { @@ -507,7 +507,7 @@ public abstract class ObjectUtils {
}
int hash = INITIAL_HASH;
for (float element : array) {
hash = MULTIPLIER * hash + hashCode(element);
hash = MULTIPLIER * hash + Float.hashCode(element);
}
return hash;
}
@ -537,7 +537,7 @@ public abstract class ObjectUtils { @@ -537,7 +537,7 @@ public abstract class ObjectUtils {
}
int hash = INITIAL_HASH;
for (long element : array) {
hash = MULTIPLIER * hash + hashCode(element);
hash = MULTIPLIER * hash + Long.hashCode(element);
}
return hash;
}
@ -558,35 +558,39 @@ public abstract class ObjectUtils { @@ -558,35 +558,39 @@ public abstract class ObjectUtils {
}
/**
* Return the same value as {@link Boolean#hashCode()}}.
* @see Boolean#hashCode()
* Return the same value as {@link Boolean#hashCode(boolean)}}.
* @deprecated as of Spring Framework 5.0, in favor of the native JDK 8 variant
*/
@Deprecated
public static int hashCode(boolean bool) {
return (bool ? 1231 : 1237);
return Boolean.hashCode(bool);
}
/**
* Return the same value as {@link Double#hashCode()}}.
* @see Double#hashCode()
* Return the same value as {@link Double#hashCode(double)}}.
* @deprecated as of Spring Framework 5.0, in favor of the native JDK 8 variant
*/
@Deprecated
public static int hashCode(double dbl) {
return hashCode(Double.doubleToLongBits(dbl));
return Double.hashCode(dbl);
}
/**
* Return the same value as {@link Float#hashCode()}}.
* @see Float#hashCode()
* Return the same value as {@link Float#hashCode(float)}}.
* @deprecated as of Spring Framework 5.0, in favor of the native JDK 8 variant
*/
@Deprecated
public static int hashCode(float flt) {
return Float.floatToIntBits(flt);
return Float.hashCode(flt);
}
/**
* Return the same value as {@link Long#hashCode()}}.
* @see Long#hashCode()
* Return the same value as {@link Long#hashCode(long)}}.
* @deprecated as of Spring Framework 5.0, in favor of the native JDK 8 variant
*/
@Deprecated
public static int hashCode(long lng) {
return (int) (lng ^ (lng >>> 32));
return Long.hashCode(lng);
}

4
spring-web/src/main/java/org/springframework/http/HttpRange.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@ -321,7 +321,7 @@ public abstract class HttpRange { @@ -321,7 +321,7 @@ public abstract class HttpRange {
@Override
public int hashCode() {
return ObjectUtils.hashCode(this.suffixLength);
return Long.hashCode(this.suffixLength);
}
@Override

Loading…
Cancel
Save