|
|
|
|
@ -21,10 +21,7 @@ import java.util.Arrays;
@@ -21,10 +21,7 @@ import java.util.Arrays;
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Miscellaneous object utility methods. |
|
|
|
|
* |
|
|
|
|
* <p>Mainly for internal use within the framework; consider |
|
|
|
|
* <a href="http://jakarta.apache.org/commons/lang/">Jakarta's Commons Lang</a> |
|
|
|
|
* for a more comprehensive suite of object utilities. |
|
|
|
|
* Mainly for internal use within the framework. |
|
|
|
|
* |
|
|
|
|
* <p>Thanks to Alex Ruiz for contributing several enhancements to this class! |
|
|
|
|
* |
|
|
|
|
@ -34,7 +31,6 @@ import java.util.Arrays;
@@ -34,7 +31,6 @@ import java.util.Arrays;
|
|
|
|
|
* @author Rob Harrop |
|
|
|
|
* @author Chris Beams |
|
|
|
|
* @since 19.03.2004 |
|
|
|
|
* @see org.apache.commons.lang.ObjectUtils |
|
|
|
|
*/ |
|
|
|
|
public abstract class ObjectUtils { |
|
|
|
|
|
|
|
|
|
@ -177,7 +173,7 @@ public abstract class ObjectUtils {
@@ -177,7 +173,7 @@ public abstract class ObjectUtils {
|
|
|
|
|
* @param obj the object to append |
|
|
|
|
* @return the new array (of the same component type; never {@code null}) |
|
|
|
|
*/ |
|
|
|
|
public static <A,O extends A> A[] addObjectToArray(A[] array, O obj) { |
|
|
|
|
public static <A, O extends A> A[] addObjectToArray(A[] array, O obj) { |
|
|
|
|
Class<?> compType = Object.class; |
|
|
|
|
if (array != null) { |
|
|
|
|
compType = array.getClass().getComponentType(); |
|
|
|
|
@ -345,9 +341,8 @@ public abstract class ObjectUtils {
@@ -345,9 +341,8 @@ public abstract class ObjectUtils {
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
int hash = INITIAL_HASH; |
|
|
|
|
int arraySize = array.length; |
|
|
|
|
for (int i = 0; i < arraySize; i++) { |
|
|
|
|
hash = MULTIPLIER * hash + nullSafeHashCode(array[i]); |
|
|
|
|
for (Object element : array) { |
|
|
|
|
hash = MULTIPLIER * hash + nullSafeHashCode(element); |
|
|
|
|
} |
|
|
|
|
return hash; |
|
|
|
|
} |
|
|
|
|
@ -361,9 +356,8 @@ public abstract class ObjectUtils {
@@ -361,9 +356,8 @@ public abstract class ObjectUtils {
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
int hash = INITIAL_HASH; |
|
|
|
|
int arraySize = array.length; |
|
|
|
|
for (int i = 0; i < arraySize; i++) { |
|
|
|
|
hash = MULTIPLIER * hash + hashCode(array[i]); |
|
|
|
|
for (boolean element : array) { |
|
|
|
|
hash = MULTIPLIER * hash + hashCode(element); |
|
|
|
|
} |
|
|
|
|
return hash; |
|
|
|
|
} |
|
|
|
|
@ -377,9 +371,8 @@ public abstract class ObjectUtils {
@@ -377,9 +371,8 @@ public abstract class ObjectUtils {
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
int hash = INITIAL_HASH; |
|
|
|
|
int arraySize = array.length; |
|
|
|
|
for (int i = 0; i < arraySize; i++) { |
|
|
|
|
hash = MULTIPLIER * hash + array[i]; |
|
|
|
|
for (byte element : array) { |
|
|
|
|
hash = MULTIPLIER * hash + element; |
|
|
|
|
} |
|
|
|
|
return hash; |
|
|
|
|
} |
|
|
|
|
@ -393,9 +386,8 @@ public abstract class ObjectUtils {
@@ -393,9 +386,8 @@ public abstract class ObjectUtils {
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
int hash = INITIAL_HASH; |
|
|
|
|
int arraySize = array.length; |
|
|
|
|
for (int i = 0; i < arraySize; i++) { |
|
|
|
|
hash = MULTIPLIER * hash + array[i]; |
|
|
|
|
for (char element : array) { |
|
|
|
|
hash = MULTIPLIER * hash + element; |
|
|
|
|
} |
|
|
|
|
return hash; |
|
|
|
|
} |
|
|
|
|
@ -409,9 +401,8 @@ public abstract class ObjectUtils {
@@ -409,9 +401,8 @@ public abstract class ObjectUtils {
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
int hash = INITIAL_HASH; |
|
|
|
|
int arraySize = array.length; |
|
|
|
|
for (int i = 0; i < arraySize; i++) { |
|
|
|
|
hash = MULTIPLIER * hash + hashCode(array[i]); |
|
|
|
|
for (double element : array) { |
|
|
|
|
hash = MULTIPLIER * hash + hashCode(element); |
|
|
|
|
} |
|
|
|
|
return hash; |
|
|
|
|
} |
|
|
|
|
@ -425,9 +416,8 @@ public abstract class ObjectUtils {
@@ -425,9 +416,8 @@ public abstract class ObjectUtils {
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
int hash = INITIAL_HASH; |
|
|
|
|
int arraySize = array.length; |
|
|
|
|
for (int i = 0; i < arraySize; i++) { |
|
|
|
|
hash = MULTIPLIER * hash + hashCode(array[i]); |
|
|
|
|
for (float element : array) { |
|
|
|
|
hash = MULTIPLIER * hash + hashCode(element); |
|
|
|
|
} |
|
|
|
|
return hash; |
|
|
|
|
} |
|
|
|
|
@ -441,9 +431,8 @@ public abstract class ObjectUtils {
@@ -441,9 +431,8 @@ public abstract class ObjectUtils {
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
int hash = INITIAL_HASH; |
|
|
|
|
int arraySize = array.length; |
|
|
|
|
for (int i = 0; i < arraySize; i++) { |
|
|
|
|
hash = MULTIPLIER * hash + array[i]; |
|
|
|
|
for (int element : array) { |
|
|
|
|
hash = MULTIPLIER * hash + element; |
|
|
|
|
} |
|
|
|
|
return hash; |
|
|
|
|
} |
|
|
|
|
@ -457,9 +446,8 @@ public abstract class ObjectUtils {
@@ -457,9 +446,8 @@ public abstract class ObjectUtils {
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
int hash = INITIAL_HASH; |
|
|
|
|
int arraySize = array.length; |
|
|
|
|
for (int i = 0; i < arraySize; i++) { |
|
|
|
|
hash = MULTIPLIER * hash + hashCode(array[i]); |
|
|
|
|
for (long element : array) { |
|
|
|
|
hash = MULTIPLIER * hash + hashCode(element); |
|
|
|
|
} |
|
|
|
|
return hash; |
|
|
|
|
} |
|
|
|
|
@ -473,9 +461,8 @@ public abstract class ObjectUtils {
@@ -473,9 +461,8 @@ public abstract class ObjectUtils {
|
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
int hash = INITIAL_HASH; |
|
|
|
|
int arraySize = array.length; |
|
|
|
|
for (int i = 0; i < arraySize; i++) { |
|
|
|
|
hash = MULTIPLIER * hash + array[i]; |
|
|
|
|
for (short element : array) { |
|
|
|
|
hash = MULTIPLIER * hash + element; |
|
|
|
|
} |
|
|
|
|
return hash; |
|
|
|
|
} |
|
|
|
|
@ -485,7 +472,7 @@ public abstract class ObjectUtils {
@@ -485,7 +472,7 @@ public abstract class ObjectUtils {
|
|
|
|
|
* @see Boolean#hashCode() |
|
|
|
|
*/ |
|
|
|
|
public static int hashCode(boolean bool) { |
|
|
|
|
return bool ? 1231 : 1237; |
|
|
|
|
return (bool ? 1231 : 1237); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -493,8 +480,7 @@ public abstract class ObjectUtils {
@@ -493,8 +480,7 @@ public abstract class ObjectUtils {
|
|
|
|
|
* @see Double#hashCode() |
|
|
|
|
*/ |
|
|
|
|
public static int hashCode(double dbl) { |
|
|
|
|
long bits = Double.doubleToLongBits(dbl); |
|
|
|
|
return hashCode(bits); |
|
|
|
|
return hashCode(Double.doubleToLongBits(dbl)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|