more varargs-related updates

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1090813 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Matthew Jason Benson 2011-04-10 15:03:23 +00:00
parent a681d650f6
commit 880c74f3a3
4 changed files with 16 additions and 175 deletions

View File

@ -132,7 +132,7 @@ public class CompareToBuilder implements Builder<Integer> {
* with <code>lhs</code>
*/
public static int reflectionCompare(Object lhs, Object rhs) {
return reflectionCompare(lhs, rhs, false, null, null);
return reflectionCompare(lhs, rhs, false, null);
}
/**
@ -164,7 +164,7 @@ public class CompareToBuilder implements Builder<Integer> {
* with <code>lhs</code>
*/
public static int reflectionCompare(Object lhs, Object rhs, boolean compareTransients) {
return reflectionCompare(lhs, rhs, compareTransients, null, null);
return reflectionCompare(lhs, rhs, compareTransients, null);
}
/**
@ -229,46 +229,10 @@ public class CompareToBuilder implements Builder<Integer> {
* with <code>lhs</code>
* @since 2.2
*/
public static int reflectionCompare(Object lhs, Object rhs, String[] excludeFields) {
public static int reflectionCompare(Object lhs, Object rhs, String... excludeFields) {
return reflectionCompare(lhs, rhs, false, null, excludeFields);
}
/**
* <p>Compares two <code>Object</code>s via reflection.</p>
*
* <p>Fields can be private, thus <code>AccessibleObject.setAccessible</code>
* is used to bypass normal access control checks. This will fail under a
* security manager unless the appropriate permissions are set.</p>
*
* <ul>
* <li>Static fields will not be compared</li>
* <li>If the <code>compareTransients</code> is <code>true</code>,
* compares transient members. Otherwise ignores them, as they
* are likely derived fields.</li>
* <li>Compares superclass fields up to and including <code>reflectUpToClass</code>.
* If <code>reflectUpToClass</code> is <code>null</code>, compares all superclass fields.</li>
* </ul>
*
* <p>If both <code>lhs</code> and <code>rhs</code> are <code>null</code>,
* they are considered equal.</p>
*
* @param lhs left-hand object
* @param rhs right-hand object
* @param compareTransients whether to compare transient fields
* @param reflectUpToClass last superclass for which fields are compared
* @return a negative integer, zero, or a positive integer as <code>lhs</code>
* is less than, equal to, or greater than <code>rhs</code>
* @throws NullPointerException if either <code>lhs</code> or <code>rhs</code>
* (but not both) is <code>null</code>
* @throws ClassCastException if <code>rhs</code> is not assignment-compatible
* with <code>lhs</code>
* @since 2.0
*/
public static int reflectionCompare(
Object lhs, Object rhs, boolean compareTransients, Class<?> reflectUpToClass) {
return reflectionCompare(lhs, rhs, compareTransients, reflectUpToClass, null);
}
/**
* <p>Compares two <code>Object</code>s via reflection.</p>
*
@ -299,14 +263,14 @@ public class CompareToBuilder implements Builder<Integer> {
* (but not both) is <code>null</code>
* @throws ClassCastException if <code>rhs</code> is not assignment-compatible
* with <code>lhs</code>
* @since 2.2
* @since 2.2 (2.0 as <code>reflectionCompare(Object, Object, boolean, Class)</code>)
*/
public static int reflectionCompare(
Object lhs,
Object rhs,
boolean compareTransients,
Class<?> reflectUpToClass,
String[] excludeFields) {
String... excludeFields) {
if (lhs == rhs) {
return 0;

View File

@ -225,28 +225,6 @@ public class EqualsBuilder implements Builder<Boolean> {
//-------------------------------------------------------------------------
/**
* <p>This method uses reflection to determine if the two <code>Object</code>s
* are equal.</p>
*
* <p>It uses <code>AccessibleObject.setAccessible</code> to gain access to private
* fields. This means that it will throw a security exception if run under
* a security manager, if the permissions are not set up correctly. It is also
* not as efficient as testing explicitly.</p>
*
* <p>Transient members will be not be tested, as they are likely derived
* fields, and not part of the value of the Object.</p>
*
* <p>Static fields will not be tested. Superclass fields will be included.</p>
*
* @param lhs <code>this</code> object
* @param rhs the other object
* @return <code>true</code> if the two Objects have tested equals.
*/
public static boolean reflectionEquals(Object lhs, Object rhs) {
return reflectionEquals(lhs, rhs, false, null, null);
}
/**
* <p>This method uses reflection to determine if the two <code>Object</code>s
* are equal.</p>
@ -289,7 +267,7 @@ public class EqualsBuilder implements Builder<Boolean> {
* @param excludeFields array of field names to exclude from testing
* @return <code>true</code> if the two Objects have tested equals.
*/
public static boolean reflectionEquals(Object lhs, Object rhs, String[] excludeFields) {
public static boolean reflectionEquals(Object lhs, Object rhs, String... excludeFields) {
return reflectionEquals(lhs, rhs, false, null, excludeFields);
}
@ -314,36 +292,7 @@ public class EqualsBuilder implements Builder<Boolean> {
* @return <code>true</code> if the two Objects have tested equals.
*/
public static boolean reflectionEquals(Object lhs, Object rhs, boolean testTransients) {
return reflectionEquals(lhs, rhs, testTransients, null, null);
}
/**
* <p>This method uses reflection to determine if the two <code>Object</code>s
* are equal.</p>
*
* <p>It uses <code>AccessibleObject.setAccessible</code> to gain access to private
* fields. This means that it will throw a security exception if run under
* a security manager, if the permissions are not set up correctly. It is also
* not as efficient as testing explicitly.</p>
*
* <p>If the testTransients parameter is set to <code>true</code>, transient
* members will be tested, otherwise they are ignored, as they are likely
* derived fields, and not part of the value of the <code>Object</code>.</p>
*
* <p>Static fields will not be included. Superclass fields will be appended
* up to and including the specified superclass. A null superclass is treated
* as java.lang.Object.</p>
*
* @param lhs <code>this</code> object
* @param rhs the other object
* @param testTransients whether to include transient fields
* @param reflectUpToClass the superclass to reflect up to (inclusive),
* may be <code>null</code>
* @return <code>true</code> if the two Objects have tested equals.
* @since 2.0
*/
public static boolean reflectionEquals(Object lhs, Object rhs, boolean testTransients, Class<?> reflectUpToClass) {
return reflectionEquals(lhs, rhs, testTransients, reflectUpToClass, null);
return reflectionEquals(lhs, rhs, testTransients, null);
}
/**
@ -373,7 +322,7 @@ public class EqualsBuilder implements Builder<Boolean> {
* @since 2.0
*/
public static boolean reflectionEquals(Object lhs, Object rhs, boolean testTransients, Class<?> reflectUpToClass,
String[] excludeFields) {
String... excludeFields) {
if (lhs == rhs) {
return true;
}

View File

@ -235,7 +235,7 @@ public class HashCodeBuilder implements Builder<Integer> {
* if the number is zero or even
*/
public static int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, Object object) {
return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null, null);
return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, false, null);
}
/**
@ -279,32 +279,7 @@ public class HashCodeBuilder implements Builder<Integer> {
*/
public static int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, Object object,
boolean testTransients) {
return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null,
null);
}
/**
* Calls {@link #reflectionHashCode(int, int, Object, boolean, Class, String[])} with excludeFields set to
* <code>null</code>.
*
* @param <T>
* the type of the object involved
* @param initialNonZeroOddNumber
* a non-zero, odd number used as the initial value
* @param multiplierNonZeroOddNumber
* a non-zero, odd number used as the multiplier
* @param object
* the Object to create a <code>hashCode</code> for
* @param testTransients
* whether to include transient fields
* @param reflectUpToClass
* the superclass to reflect up to (inclusive), may be <code>null</code>
* @return int hash code
*/
public static <T> int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, T object,
boolean testTransients, Class<? super T> reflectUpToClass) {
return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients,
reflectUpToClass, null);
return reflectionHashCode(initialNonZeroOddNumber, multiplierNonZeroOddNumber, object, testTransients, null);
}
/**
@ -355,7 +330,7 @@ public class HashCodeBuilder implements Builder<Integer> {
* @since 2.0
*/
public static <T> int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, T object,
boolean testTransients, Class<? super T> reflectUpToClass, String[] excludeFields) {
boolean testTransients, Class<? super T> reflectUpToClass, String... excludeFields) {
if (object == null) {
throw new IllegalArgumentException("The object to build a hash code for must not be null");
@ -370,40 +345,6 @@ public class HashCodeBuilder implements Builder<Integer> {
return builder.toHashCode();
}
/**
* <p>
* This method uses reflection to build a valid hash code.
* </p>
*
* <p>
* This constructor uses two hard coded choices for the constants needed to build a hash code.
* </p>
*
* <p>
* It uses <code>AccessibleObject.setAccessible</code> to gain access to private fields. This means that it will
* throw a security exception if run under a security manager, if the permissions are not set up correctly. It is
* also not as efficient as testing explicitly.
* </p>
*
* <p>
* Transient members will be not be used, as they are likely derived fields, and not part of the value of the
* <code>Object</code>.
* </p>
*
* <p>
* Static fields will not be tested. Superclass fields will be included.
* </p>
*
* @param object
* the Object to create a <code>hashCode</code> for
* @return int hash code
* @throws IllegalArgumentException
* if the object is <code>null</code>
*/
public static int reflectionHashCode(Object object) {
return reflectionHashCode(17, 37, object, false, null, null);
}
/**
* <p>
* This method uses reflection to build a valid hash code.
@ -437,7 +378,7 @@ public class HashCodeBuilder implements Builder<Integer> {
* if the object is <code>null</code>
*/
public static int reflectionHashCode(Object object, boolean testTransients) {
return reflectionHashCode(17, 37, object, testTransients, null, null);
return reflectionHashCode(17, 37, object, testTransients, null);
}
/**
@ -510,7 +451,7 @@ public class HashCodeBuilder implements Builder<Integer> {
* @throws IllegalArgumentException
* if the object is <code>null</code>
*/
public static int reflectionHashCode(Object object, String[] excludeFields) {
public static int reflectionHashCode(Object object, String... excludeFields) {
return reflectionHashCode(17, 37, object, false, null, excludeFields);
}

View File

@ -289,19 +289,6 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
.toString();
}
/**
* Builds a String for a toString method excluding the given field name.
*
* @param object
* The object to "toString".
* @param excludeFieldName
* The field name to exclude
* @return The toString value.
*/
public static String toStringExclude(Object object, final String excludeFieldName) {
return toStringExclude(object, new String[] { excludeFieldName });
}
/**
* Builds a String for a toString method excluding the given field names.
*
@ -360,7 +347,7 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
* The field names to exclude
* @return The toString value.
*/
public static String toStringExclude(Object object, String[] excludeFieldNames) {
public static String toStringExclude(Object object, String... excludeFieldNames) {
return new ReflectionToStringBuilder(object).setExcludeFieldNames(excludeFieldNames).toString();
}
@ -657,11 +644,11 @@ public class ReflectionToStringBuilder extends ToStringBuilder {
* The excludeFieldNames to excluding from toString or <code>null</code>.
* @return <code>this</code>
*/
public ReflectionToStringBuilder setExcludeFieldNames(String[] excludeFieldNamesParam) {
public ReflectionToStringBuilder setExcludeFieldNames(String... excludeFieldNamesParam) {
if (excludeFieldNamesParam == null) {
this.excludeFieldNames = null;
} else {
this.excludeFieldNames = toNoNullStringArray(excludeFieldNamesParam);
this.excludeFieldNames = excludeFieldNamesParam.clone();
Arrays.sort(this.excludeFieldNames);
}
return this;