From e9627a10c7fdbc263601fdd9f0f783b41389ff5d Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 4 Apr 2017 17:16:50 +0200 Subject: [PATCH] Deprecate ObjectUtils.hashCode for primitives in favor of JDK 8's hashCode methods Issue: SPR-15395 --- .../org/springframework/util/ObjectUtils.java | 36 ++++++++++--------- .../org/springframework/http/HttpRange.java | 4 +-- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java index 801f167f97..f85af56978 100644 --- a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java @@ -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 { } 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 { } 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 { } 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 { } /** - * 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); } diff --git a/spring-web/src/main/java/org/springframework/http/HttpRange.java b/spring-web/src/main/java/org/springframework/http/HttpRange.java index 02e7f10859..4c6131dd0d 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpRange.java +++ b/spring-web/src/main/java/org/springframework/http/HttpRange.java @@ -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 { @Override public int hashCode() { - return ObjectUtils.hashCode(this.suffixLength); + return Long.hashCode(this.suffixLength); } @Override