You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mb...@apache.org on 2011/04/10 17:03:23 UTC
svn commit: r1090813 - in
/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder:
CompareToBuilder.java EqualsBuilder.java HashCodeBuilder.java
ReflectionToStringBuilder.java
Author: mbenson
Date: Sun Apr 10 15:03:23 2011
New Revision: 1090813
URL: http://svn.apache.org/viewvc?rev=1090813&view=rev
Log:
more varargs-related updates
Modified:
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java
Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java?rev=1090813&r1=1090812&r2=1090813&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/CompareToBuilder.java Sun Apr 10 15:03:23 2011
@@ -132,7 +132,7 @@ public class CompareToBuilder implements
* 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
* 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,7 +229,7 @@ public class CompareToBuilder implements
* 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);
}
@@ -256,42 +256,6 @@ public class CompareToBuilder implements
* @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>
- *
- * <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
* @param excludeFields fields to exclude
* @return a negative integer, zero, or a positive integer as <code>lhs</code>
* is less than, equal to, or greater than <code>rhs</code>
@@ -299,14 +263,14 @@ public class CompareToBuilder implements
* (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;
Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java?rev=1090813&r1=1090812&r2=1090813&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/EqualsBuilder.java Sun Apr 10 15:03:23 2011
@@ -241,28 +241,6 @@ public class EqualsBuilder implements Bu
*
* @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>
- *
- * <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
* @param excludeFields Collection of String field names to exclude from testing
* @return <code>true</code> if the two Objects have tested equals.
*/
@@ -289,7 +267,7 @@ public class EqualsBuilder implements Bu
* @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 Bu
* @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 Bu
* @since 2.0
*/
public static boolean reflectionEquals(Object lhs, Object rhs, boolean testTransients, Class<?> reflectUpToClass,
- String[] excludeFields) {
+ String... excludeFields) {
if (lhs == rhs) {
return true;
}
Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java?rev=1090813&r1=1090812&r2=1090813&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/HashCodeBuilder.java Sun Apr 10 15:03:23 2011
@@ -235,7 +235,7 @@ public class HashCodeBuilder implements
* 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
*/
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
* @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");
@@ -385,40 +360,6 @@ public class HashCodeBuilder implements
* 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.
- * </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>
* 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>.
@@ -437,7 +378,7 @@ public class HashCodeBuilder implements
* 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
* @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);
}
Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java?rev=1090813&r1=1090812&r2=1090813&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java (original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/builder/ReflectionToStringBuilder.java Sun Apr 10 15:03:23 2011
@@ -290,19 +290,6 @@ public class ReflectionToStringBuilder e
}
/**
- * 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.
*
* @param object
@@ -360,7 +347,7 @@ public class ReflectionToStringBuilder e
* 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 e
* 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;