diff --git a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java index 277a5a0fb..1ef034bb4 100644 --- a/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java @@ -132,7 +132,7 @@ public class CompareToBuilder implements Builder { * with lhs */ 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 { * with lhs */ 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 { * with lhs * @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); } - /** - *

Compares two Objects via reflection.

- * - *

Fields can be private, thus AccessibleObject.setAccessible - * is used to bypass normal access control checks. This will fail under a - * security manager unless the appropriate permissions are set.

- * - *
    - *
  • Static fields will not be compared
  • - *
  • If the compareTransients is true, - * compares transient members. Otherwise ignores them, as they - * are likely derived fields.
  • - *
  • Compares superclass fields up to and including reflectUpToClass. - * If reflectUpToClass is null, compares all superclass fields.
  • - *
- * - *

If both lhs and rhs are null, - * they are considered equal.

- * - * @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 lhs - * is less than, equal to, or greater than rhs - * @throws NullPointerException if either lhs or rhs - * (but not both) is null - * @throws ClassCastException if rhs is not assignment-compatible - * with lhs - * @since 2.0 - */ - public static int reflectionCompare( - Object lhs, Object rhs, boolean compareTransients, Class reflectUpToClass) { - return reflectionCompare(lhs, rhs, compareTransients, reflectUpToClass, null); - } - /** *

Compares two Objects via reflection.

* @@ -299,14 +263,14 @@ public class CompareToBuilder implements Builder { * (but not both) is null * @throws ClassCastException if rhs is not assignment-compatible * with lhs - * @since 2.2 + * @since 2.2 (2.0 as reflectionCompare(Object, Object, boolean, Class)) */ public static int reflectionCompare( Object lhs, Object rhs, boolean compareTransients, Class reflectUpToClass, - String[] excludeFields) { + String... excludeFields) { if (lhs == rhs) { return 0; diff --git a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java index d40e1e28b..fef4e8621 100644 --- a/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java @@ -225,28 +225,6 @@ public class EqualsBuilder implements Builder { //------------------------------------------------------------------------- - /** - *

This method uses reflection to determine if the two Objects - * are equal.

- * - *

It uses AccessibleObject.setAccessible 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.

- * - *

Transient members will be not be tested, as they are likely derived - * fields, and not part of the value of the Object.

- * - *

Static fields will not be tested. Superclass fields will be included.

- * - * @param lhs this object - * @param rhs the other object - * @return true if the two Objects have tested equals. - */ - public static boolean reflectionEquals(Object lhs, Object rhs) { - return reflectionEquals(lhs, rhs, false, null, null); - } - /** *

This method uses reflection to determine if the two Objects * are equal.

@@ -289,7 +267,7 @@ public class EqualsBuilder implements Builder { * @param excludeFields array of field names to exclude from testing * @return true 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 { * @return true if the two Objects have tested equals. */ public static boolean reflectionEquals(Object lhs, Object rhs, boolean testTransients) { - return reflectionEquals(lhs, rhs, testTransients, null, null); - } - - /** - *

This method uses reflection to determine if the two Objects - * are equal.

- * - *

It uses AccessibleObject.setAccessible 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.

- * - *

If the testTransients parameter is set to true, transient - * members will be tested, otherwise they are ignored, as they are likely - * derived fields, and not part of the value of the Object.

- * - *

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.

- * - * @param lhs this object - * @param rhs the other object - * @param testTransients whether to include transient fields - * @param reflectUpToClass the superclass to reflect up to (inclusive), - * may be null - * @return true 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 { * @since 2.0 */ public static boolean reflectionEquals(Object lhs, Object rhs, boolean testTransients, Class reflectUpToClass, - String[] excludeFields) { + String... excludeFields) { if (lhs == rhs) { return true; } diff --git a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java index e726bb3c1..4607d04e2 100644 --- a/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java @@ -235,7 +235,7 @@ public class HashCodeBuilder implements Builder { * 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 { */ 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 - * null. - * - * @param - * 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 hashCode for - * @param testTransients - * whether to include transient fields - * @param reflectUpToClass - * the superclass to reflect up to (inclusive), may be null - * @return int hash code - */ - public static int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, T object, - boolean testTransients, Class 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 { * @since 2.0 */ public static int reflectionHashCode(int initialNonZeroOddNumber, int multiplierNonZeroOddNumber, T object, - boolean testTransients, Class reflectUpToClass, String[] excludeFields) { + boolean testTransients, Class 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 { return builder.toHashCode(); } - /** - *

- * This method uses reflection to build a valid hash code. - *

- * - *

- * This constructor uses two hard coded choices for the constants needed to build a hash code. - *

- * - *

- * It uses AccessibleObject.setAccessible 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. - *

- * - *

- * Transient members will be not be used, as they are likely derived fields, and not part of the value of the - * Object. - *

- * - *

- * Static fields will not be tested. Superclass fields will be included. - *

- * - * @param object - * the Object to create a hashCode for - * @return int hash code - * @throws IllegalArgumentException - * if the object is null - */ - public static int reflectionHashCode(Object object) { - return reflectionHashCode(17, 37, object, false, null, null); - } - /** *

* This method uses reflection to build a valid hash code. @@ -437,7 +378,7 @@ public class HashCodeBuilder implements Builder { * if the object is null */ 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 { * @throws IllegalArgumentException * if the object is null */ - public static int reflectionHashCode(Object object, String[] excludeFields) { + public static int reflectionHashCode(Object object, String... excludeFields) { return reflectionHashCode(17, 37, object, false, null, excludeFields); } diff --git a/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java b/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java index 9b1703a01..b47049ca6 100644 --- a/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java +++ b/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java @@ -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 null. * @return this */ - 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;