bayard 2003/01/15 12:51:57
Modified: lang/src/java/org/apache/commons/lang/builder
HashCodeBuilder.java
Log:
Javadoc patch for java example.
Submitted by: Christopher M. Judd <[EMAIL PROTECTED]>
Revision Changes Path
1.8 +27 -27
jakarta-commons/lang/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java
Index: HashCodeBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/builder/HashCodeBuilder.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- HashCodeBuilder.java 23 Dec 2002 00:20:31 -0000 1.7
+++ HashCodeBuilder.java 15 Jan 2003 20:51:57 -0000 1.8
@@ -76,7 +76,7 @@
* int age;
* boolean isSmoker;
* ...
- *
+ *
* public int hashCode() {
* // you pick a hard-coded, randomly chosen, non-zero, odd number
* // ideally different for each class
@@ -88,29 +88,29 @@
* }
* }
* </pre>
- *
+ *
* <p>If required, the superclass hashCode can be added using {@link
#appendSuper}.</p>
*
* <p>Alternatively, there is a method that uses reflection to determine
- * the fields to test. Because these fields are usually private, the method,
+ * the fields to test. Because these fields are usually private, the method,
* <code>reflectionHashCode</code>, uses <code>Field.setAccessible</code> to
- * change the visibility of the fields. This will fail under a security manager,
+ * change the visibility of the fields. This will fail under a security manager,
* unless the appropriate permissions are set up correctly. It is also slower
* than testing explicitly.</p>
*
* <p>A typical invocation for this method would look like:</p>
* <pre>
- * public boolean hashCode(Object o) {
+ * public int hashCode() {
* return HashCodeBuilder.reflectionHashCode(this);
* }
* </pre>
- *
+ *
* @author Stephen Colebourne
* @since 1.0
* @version $Id$
*/
public class HashCodeBuilder {
-
+
/**
* Constant to use in building the hashCode
*/
@@ -119,7 +119,7 @@
* Running total of the hashCode
*/
private int iTotal = 0;
-
+
/**
* <p>Constructor for HashCodeBuilder.</p>
*
@@ -131,7 +131,7 @@
iConstant = 37;
iTotal = 17;
}
-
+
/**
* <p>Constructor for <code>HashCodeBuilder</code>.</p>
*
@@ -140,7 +140,7 @@
* not vital.</p>
*
* <p>Prime numbers are preferred, especially for the multiplier.</p>
- *
+ *
* @param initialNonZeroOddNumber a non-zero, odd number used as the initial
value
* @param multiplierNonZeroOddNumber a non-zero, odd number used as the
multiplier
* @throws IllegalArgumentException if the number is zero or even
@@ -164,7 +164,7 @@
}
//-------------------------------------------------------------------------
-
+
/**
* <p>This method uses reflection to build a valid hash code.</p>
*
@@ -214,7 +214,7 @@
public static int reflectionHashCode(Object object, boolean testTransients) {
return reflectionHashCode(17, 37, object, testTransients);
}
-
+
/**
* <p>This method uses reflection to build a valid hash code.</p>
*
@@ -231,7 +231,7 @@
* <p>Two randomly chosen, non-zero, odd numbers must be passed in. Ideally
* these should be different for each class, however this is not vital.
* Prime numbers are preferred, especially for the multiplier.</p>
- *
+ *
* @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
@@ -240,11 +240,11 @@
* @throws IllegalArgumentException if the number is zero or even
*/
public static int reflectionHashCode(
- int initialNonZeroOddNumber, int multiplierNonZeroOddNumber,
+ int initialNonZeroOddNumber, int multiplierNonZeroOddNumber,
Object object) {
return reflectionHashCode(initialNonZeroOddNumber,
multiplierNonZeroOddNumber, object, false);
}
-
+
/**
* <p>This method uses reflection to build a valid hash code.</p>
*
@@ -262,7 +262,7 @@
* <p>Two randomly chosen, non-zero, odd numbers must be passed in. Ideally
* these should be different for each class, however this is not vital.
* Prime numbers are preferred, especially for the multiplier.</p>
- *
+ *
* @param initialNonZeroOddNumber
* @param multiplierNonZeroOddNumber
* @param object the Object to create a <code>hashCode</code> for
@@ -274,7 +274,7 @@
public static int reflectionHashCode(
int initialNonZeroOddNumber, int multiplierNonZeroOddNumber,
Object object, boolean testTransients) {
-
+
if (object == null) {
throw new IllegalArgumentException("The object to build a hash code for
must not be null");
}
@@ -299,7 +299,7 @@
}
//-------------------------------------------------------------------------
-
+
/**
* <p>Adds the result of super.hashCode() to this builder.</p>
*
@@ -310,9 +310,9 @@
iTotal = iTotal * iConstant + superHashCode;
return this;
}
-
+
//-------------------------------------------------------------------------
-
+
/**
* <p>Append a <code>hashCode</code> for an <code>Object</code>.</p>
*
@@ -322,12 +322,12 @@
public HashCodeBuilder append(Object object) {
if (object == null) {
iTotal = iTotal * iConstant;
-
+
} else {
if (object.getClass().isArray() == false) {
- //the simple case, not an array, just the element
+ //the simple case, not an array, just the element
iTotal = iTotal * iConstant + object.hashCode();
-
+
} else {
//'Switch' on type of array, to dispatch to the correct handler
// This handles multi dimensional arrays
@@ -347,7 +347,7 @@
append((float[]) object);
} else if (object instanceof boolean[]) {
append((boolean[]) object);
- } else {
+ } else {
// Not an array of primitives
append((Object[]) object);
}
@@ -598,9 +598,9 @@
/**
* <p>Return the computed <code>hashCode</code>.</p>
- *
+ *
* @return <code>hashCode</code> based on the fields appended
- */
+ */
public int toHashCode() {
return iTotal;
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>