directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r370807 [12/22] - in /directory/sandbox/trustin/mina-spi: ./ core/src/main/java/org/apache/mina/common/ core/src/main/java/org/apache/mina/common/support/ core/src/main/java/org/apache/mina/common/support/discovery/ core/src/main/java/org/a...
Date Fri, 20 Jan 2006 13:48:55 GMT
Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/WordUtils.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/WordUtils.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/WordUtils.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/WordUtils.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,513 @@
+/*
+ * Copyright 2002-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.mina.common.support.lang;
+
+/**
+ * <p>Operations on Strings that contain words.</p>
+ * 
+ * <p>This class tries to handle <code>null</code> input gracefully.
+ * An exception will not be thrown for a <code>null</code> input.
+ * Each method documents its behaviour in more detail.</p>
+ * 
+ * @author Apache Jakarta Velocity
+ * @author Henri Yandell
+ * @author Stephen Colebourne
+ * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
+ * @author Gary Gregory
+ * @since 2.0
+ * @version $Id$
+ */
+public class WordUtils {
+
+    /**
+     * <p><code>WordUtils</code> instances should NOT be constructed in
+     * standard programming. Instead, the class should be used as
+     * <code>WordUtils.wrap("foo bar", 20);</code>.</p>
+     *
+     * <p>This constructor is public to permit tools that require a JavaBean
+     * instance to operate.</p>
+     */
+    public WordUtils() {
+    }
+
+    // Wrapping
+    //--------------------------------------------------------------------------
+//    /**
+//     * <p>Wraps a block of text to a specified line length using '\n' as
+//     * a newline.</p>
+//     *
+//     * <p>This method takes a block of text, which might have long lines in it
+//     * and wraps the long lines based on the supplied lineLength parameter.</p>
+//     * 
+//     * <p>If a single word is longer than the line length (eg. a URL), it will
+//     * not be broken, and will display beyond the expected width.</p>
+//     * 
+//     * <p>If there are tabs in inString, you are going to get results that are
+//     * a bit strange. Tabs are a single character but are displayed as 4 or 8
+//     * spaces. Remove the tabs.</p>
+//     *
+//     * @param str  text which is in need of word-wrapping, may be null
+//     * @param lineLength  the column to wrap the words at
+//     * @return the text with all the long lines word-wrapped
+//     *  <code>null</code> if null string input
+//     */
+//    public static String wrapText(String str, int lineLength) {
+//        return wrap(str, null, lineLength);
+//    }
+    
+//    /**
+//     * <p>Wraps a block of text to a specified line length.</p>
+//     *
+//     * <p>This method takes a block of text, which might have long lines in it
+//     * and wraps the long lines based on the supplied lineLength parameter.</p>
+//     * 
+//     * <p>If a single word is longer than the wrapColumn (eg. a URL), it will
+//     * not be broken, and will display beyond the expected width.</p>
+//     * 
+//     * <p>If there are tabs in inString, you are going to get results that are
+//     * a bit strange. Tabs are a single character but are displayed as 4 or 8
+//     * spaces. Remove the tabs.</p>
+//     *
+//     * @param str  text which is in need of word-wrapping, may be null
+//     * @param newLineChars  the characters that define a newline, null treated as \n
+//     * @param lineLength  the column to wrap the words at
+//     * @return the text with all the long lines word-wrapped
+//     *  <code>null</code> if null string input
+//     */
+//    public static String wrapText(String str, String newLineChars, int lineLength) {
+//        if (str == null) {
+//            return null;
+//        }
+//        if (newLineChars == null) {
+//            newLineChars = "\n";
+//        }
+//        StringTokenizer lineTokenizer = new StringTokenizer(str, newLineChars, true);
+//        StringBuffer stringBuffer = new StringBuffer();
+//
+//        while (lineTokenizer.hasMoreTokens()) {
+//            try {
+//                String nextLine = lineTokenizer.nextToken();
+//
+//                if (nextLine.length() > lineLength) {
+//                    // This line is long enough to be wrapped.
+//                    nextLine = wrapLine(nextLine, null, lineLength, false);
+//                }
+//
+//                stringBuffer.append(nextLine);
+//
+//            } catch (NoSuchElementException nsee) {
+//                // thrown by nextToken(), but I don't know why it would
+//                break;
+//            }
+//        }
+//
+//        return stringBuffer.toString();
+//    }
+
+    // Wrapping
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Wraps a single line of text, identifying words by <code>' '</code>.</p>
+     * 
+     * <p>New lines will be separated by the system property line separator.
+     * Very long words, such as URLs will <i>not</i> be wrapped.</p>
+     * 
+     * <p>Leading spaces on a new line are stripped.
+     * Trailing spaces are not stripped.</p>
+     *
+     * <pre>
+     * WordUtils.wrap(null, *) = null
+     * WordUtils.wrap("", *) = ""
+     * </pre>
+     *
+     * @param str  the String to be word wrapped, may be null
+     * @param wrapLength  the column to wrap the words at, less than 1 is treated as 1
+     * @return a line with newlines inserted, <code>null</code> if null input
+     */
+    public static String wrap(String str, int wrapLength) {
+        return wrap(str, wrapLength, null, false);
+    }
+    
+    /**
+     * <p>Wraps a single line of text, identifying words by <code>' '</code>.</p>
+     * 
+     * <p>Leading spaces on a new line are stripped.
+     * Trailing spaces are not stripped.</p>
+     * 
+     * <pre>
+     * WordUtils.wrap(null, *, *, *) = null
+     * WordUtils.wrap("", *, *, *) = ""
+     * </pre>
+     *
+     * @param str  the String to be word wrapped, may be null
+     * @param wrapLength  the column to wrap the words at, less than 1 is treated as 1
+     * @param newLineStr  the string to insert for a new line, 
+     *  <code>null</code> uses the system property line separator
+     * @param wrapLongWords  true if long words (such as URLs) should be wrapped
+     * @return a line with newlines inserted, <code>null</code> if null input
+     */
+    public static String wrap(String str, int wrapLength, String newLineStr, boolean wrapLongWords) {
+        if (str == null) {
+            return null;
+        }
+        if (newLineStr == null) {
+            newLineStr = SystemUtils.LINE_SEPARATOR;
+        }
+        if (wrapLength < 1) {
+            wrapLength = 1;
+        }
+        int inputLineLength = str.length();
+        int offset = 0;
+        StringBuffer wrappedLine = new StringBuffer(inputLineLength + 32);
+        
+        while ((inputLineLength - offset) > wrapLength) {
+            if (str.charAt(offset) == ' ') {
+                offset++;
+                continue;
+            }
+            int spaceToWrapAt = str.lastIndexOf(' ', wrapLength + offset);
+
+            if (spaceToWrapAt >= offset) {
+                // normal case
+                wrappedLine.append(str.substring(offset, spaceToWrapAt));
+                wrappedLine.append(newLineStr);
+                offset = spaceToWrapAt + 1;
+                
+            } else {
+                // really long word or URL
+                if (wrapLongWords) {
+                    // wrap really long word one line at a time
+                    wrappedLine.append(str.substring(offset, wrapLength + offset));
+                    wrappedLine.append(newLineStr);
+                    offset += wrapLength;
+                } else {
+                    // do not wrap really long word, just extend beyond limit
+                    spaceToWrapAt = str.indexOf(' ', wrapLength + offset);
+                    if (spaceToWrapAt >= 0) {
+                        wrappedLine.append(str.substring(offset, spaceToWrapAt));
+                        wrappedLine.append(newLineStr);
+                        offset = spaceToWrapAt + 1;
+                    } else {
+                        wrappedLine.append(str.substring(offset));
+                        offset = inputLineLength;
+                    }
+                }
+            }
+        }
+
+        // Whatever is left in line is short enough to just pass through
+        wrappedLine.append(str.substring(offset));
+
+        return wrappedLine.toString();
+    }
+
+    // Capitalizing
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Capitalizes all the whitespace separated words in a String.
+     * Only the first letter of each word is changed. To convert the 
+     * rest of each word to lowercase at the same time, 
+     * use {@link #capitalizeFully(String)}.</p>
+     *
+     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.
+     * A <code>null</code> input String returns <code>null</code>.
+     * Capitalization uses the unicode title case, normally equivalent to
+     * upper case.</p>
+     *
+     * <pre>
+     * WordUtils.capitalize(null)        = null
+     * WordUtils.capitalize("")          = ""
+     * WordUtils.capitalize("i am FINE") = "I Am FINE"
+     * </pre>
+     * 
+     * @param str  the String to capitalize, may be null
+     * @return capitalized String, <code>null</code> if null String input
+     * @see #uncapitalize(String)
+     * @see #capitalizeFully(String)
+     */
+    public static String capitalize(String str) {
+        return capitalize(str, null);
+    }
+
+    /**
+     * <p>Capitalizes all the delimiter separated words in a String.
+     * Only the first letter of each word is changed. To convert the 
+     * rest of each word to lowercase at the same time, 
+     * use {@link #capitalizeFully(String, char[])}.</p>
+     *
+     * <p>The delimiters represent a set of characters understood to separate words.
+     * The first string character and the first non-delimiter character after a
+     * delimiter will be capitalized. </p>
+     *
+     * <p>A <code>null</code> input String returns <code>null</code>.
+     * Capitalization uses the unicode title case, normally equivalent to
+     * upper case.</p>
+     *
+     * <pre>
+     * WordUtils.capitalize(null, *)            = null
+     * WordUtils.capitalize("", *)              = ""
+     * WordUtils.capitalize(*, new char[0])     = *
+     * WordUtils.capitalize("i am fine", null)  = "I Am Fine"
+     * WordUtils.capitalize("i aM.fine", {'.'}) = "I aM.Fine"
+     * </pre>
+     * 
+     * @param str  the String to capitalize, may be null
+     * @param delimiters  set of characters to determine capitalization, null means whitespace
+     * @return capitalized String, <code>null</code> if null String input
+     * @see #uncapitalize(String)
+     * @see #capitalizeFully(String)
+     * @since 2.1
+     */
+    public static String capitalize(String str, char[] delimiters) {
+        if (str == null || str.length() == 0) {
+            return str;
+        }
+        int strLen = str.length();
+        StringBuffer buffer = new StringBuffer(strLen);
+
+        int delimitersLen = 0;
+        if(delimiters != null) {
+            delimitersLen = delimiters.length;
+        }
+
+        boolean capitalizeNext = true;
+        for (int i = 0; i < strLen; i++) {
+            char ch = str.charAt(i);
+
+            boolean isDelimiter = false;
+            if(delimiters == null) {
+                isDelimiter = Character.isWhitespace(ch);
+            } else {
+                for(int j=0; j < delimitersLen; j++) {
+                    if(ch == delimiters[j]) {
+                        isDelimiter = true;
+                        break;
+                    }
+                }
+            }
+
+            if (isDelimiter) {
+                buffer.append(ch);
+                capitalizeNext = true;
+            } else if (capitalizeNext) {
+                buffer.append(Character.toTitleCase(ch));
+                capitalizeNext = false;
+            } else {
+                buffer.append(ch);
+            }
+        }
+        return buffer.toString();
+    }
+
+    /**
+     * <p>Converts all the whitespace separated words in a String into capitalized words, 
+     * that is each word is made up of a titlecase character and then a series of 
+     * lowercase characters.  </p>
+     *
+     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.
+     * A <code>null</code> input String returns <code>null</code>.
+     * Capitalization uses the unicode title case, normally equivalent to
+     * upper case.</p>
+     *
+     * <pre>
+     * WordUtils.capitalizeFully(null)        = null
+     * WordUtils.capitalizeFully("")          = ""
+     * WordUtils.capitalizeFully("i am FINE") = "I Am Fine"
+     * </pre>
+     * 
+     * @param str  the String to capitalize, may be null
+     * @return capitalized String, <code>null</code> if null String input
+     */
+    public static String capitalizeFully(String str) {
+        return capitalizeFully(str, null);
+    }
+
+    /**
+     * <p>Converts all the delimiter separated words in a String into capitalized words, 
+     * that is each word is made up of a titlecase character and then a series of 
+     * lowercase characters. </p>
+     *
+     * <p>The delimiters represent a set of characters understood to separate words.
+     * The first string character and the first non-delimiter character after a
+     * delimiter will be capitalized. </p>
+     *
+     * <p>A <code>null</code> input String returns <code>null</code>.
+     * Capitalization uses the unicode title case, normally equivalent to
+     * upper case.</p>
+     *
+     * <pre>
+     * WordUtils.capitalizeFully(null, *)            = null
+     * WordUtils.capitalizeFully("", *)              = ""
+     * WordUtils.capitalizeFully(*, null)            = *
+     * WordUtils.capitalizeFully(*, new char[0])     = *
+     * WordUtils.capitalizeFully("i aM.fine", {'.'}) = "I am.Fine"
+     * </pre>
+     * 
+     * @param str  the String to capitalize, may be null
+     * @param delimiters  set of characters to determine capitalization, null means whitespace
+     * @return capitalized String, <code>null</code> if null String input
+     * @since 2.1
+     */
+    public static String capitalizeFully(String str, char[] delimiters) {
+        if (str == null || str.length() == 0) {
+            return str;
+        }
+        str = str.toLowerCase();
+        return capitalize(str, delimiters);
+    }
+
+    /**
+     * <p>Uncapitalizes all the whitespace separated words in a String.
+     * Only the first letter of each word is changed.</p>
+     *
+     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.
+     * A <code>null</code> input String returns <code>null</code>.</p>
+     *
+     * <pre>
+     * WordUtils.uncapitalize(null)        = null
+     * WordUtils.uncapitalize("")          = ""
+     * WordUtils.uncapitalize("I Am FINE") = "i am fINE"
+     * </pre>
+     * 
+     * @param str  the String to uncapitalize, may be null
+     * @return uncapitalized String, <code>null</code> if null String input
+     * @see #capitalize(String)
+     */
+    public static String uncapitalize(String str) {
+        return uncapitalize(str, null);
+    }
+
+    /**
+     * <p>Uncapitalizes all the whitespace separated words in a String.
+     * Only the first letter of each word is changed.</p>
+     *
+     * <p>The delimiters represent a set of characters understood to separate words.
+     * The first string character and the first non-delimiter character after a
+     * delimiter will be uncapitalized. </p>
+     *
+     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.
+     * A <code>null</code> input String returns <code>null</code>.</p>
+     *
+     * <pre>
+     * WordUtils.uncapitalize(null, *)            = null
+     * WordUtils.uncapitalize("", *)              = ""
+     * WordUtils.uncapitalize(*, null)            = *
+     * WordUtils.uncapitalize(*, new char[0])     = *
+     * WordUtils.uncapitalize("I AM.FINE", {'.'}) = "i AM.fINE"
+     * </pre>
+     * 
+     * @param str  the String to uncapitalize, may be null
+     * @param delimiters  set of characters to determine uncapitalization, null means whitespace
+     * @return uncapitalized String, <code>null</code> if null String input
+     * @see #capitalize(String)
+     * @since 2.1
+     */
+    public static String uncapitalize(String str, char[] delimiters) {
+        if (str == null || str.length() == 0) {
+            return str;
+        }
+        int strLen = str.length();
+
+        int delimitersLen = 0;
+        if(delimiters != null) {
+            delimitersLen = delimiters.length;
+        }
+
+        StringBuffer buffer = new StringBuffer(strLen);
+        boolean uncapitalizeNext = true;
+        for (int i = 0; i < strLen; i++) {
+            char ch = str.charAt(i);
+
+            boolean isDelimiter = false;
+            if(delimiters == null) {
+                isDelimiter = Character.isWhitespace(ch);
+            } else {
+                for(int j=0; j < delimitersLen; j++) {
+                    if(ch == delimiters[j]) {
+                        isDelimiter = true;
+                        break;
+                    }
+                }
+            }
+
+            if (isDelimiter) {
+                buffer.append(ch);
+                uncapitalizeNext = true;
+            } else if (uncapitalizeNext) {
+                buffer.append(Character.toLowerCase(ch));
+                uncapitalizeNext = false;
+            } else {
+                buffer.append(ch);
+            }
+        }
+        return buffer.toString();
+    }
+
+    /**
+     * <p>Swaps the case of a String using a word based algorithm.</p>
+     * 
+     * <ul>
+     *  <li>Upper case character converts to Lower case</li>
+     *  <li>Title case character converts to Lower case</li>
+     *  <li>Lower case character after Whitespace or at start converts to Title case</li>
+     *  <li>Other Lower case character converts to Upper case</li>
+     * </ul>
+     * 
+     * <p>Whitespace is defined by {@link Character#isWhitespace(char)}.
+     * A <code>null</code> input String returns <code>null</code>.</p>
+     * 
+     * <pre>
+     * StringUtils.swapCase(null)                 = null
+     * StringUtils.swapCase("")                   = ""
+     * StringUtils.swapCase("The dog has a BONE") = "tHE DOG HAS A bone"
+     * </pre>
+     * 
+     * @param str  the String to swap case, may be null
+     * @return the changed String, <code>null</code> if null String input
+     */
+    public static String swapCase(String str) {
+        int strLen;
+        if (str == null || (strLen = str.length()) == 0) {
+            return str;
+        }
+        StringBuffer buffer = new StringBuffer(strLen);
+
+        boolean whitespace = true;
+        char ch = 0;
+        char tmp = 0;
+
+        for (int i = 0; i < strLen; i++) {
+            ch = str.charAt(i);
+            if (Character.isUpperCase(ch)) {
+                tmp = Character.toLowerCase(ch);
+            } else if (Character.isTitleCase(ch)) {
+                tmp = Character.toLowerCase(ch);
+            } else if (Character.isLowerCase(ch)) {
+                if (whitespace) {
+                    tmp = Character.toTitleCase(ch);
+                } else {
+                    tmp = Character.toUpperCase(ch);
+                }
+            } else {
+                tmp = ch;
+            }
+            buffer.append(tmp);
+            whitespace = Character.isWhitespace(ch);
+        }
+        return buffer.toString();
+    }
+    
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/WordUtils.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/builder/CompareToBuilder.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/builder/CompareToBuilder.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/builder/CompareToBuilder.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/builder/CompareToBuilder.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,928 @@
+/*
+ * Copyright 2002-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.mina.common.support.lang.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Comparator;
+
+import org.apache.mina.common.support.lang.math.NumberUtils;
+
+/** 
+ * Assists in implementing {@link java.lang.Comparable#compareTo(Object)} methods.
+ *
+ * It is consistent with <code>equals(Object)</code> and
+ * <code>hashcode()</code> built with {@link EqualsBuilder} and
+ * {@link HashCodeBuilder}.</p>
+ *
+ * <p>Two Objects that compare equal using <code>equals(Object)</code> should normally
+ * also compare equal using <code>compareTo(Object)</code>.</p>
+ *
+ * <p>All relevant fields should be included in the calculation of the
+ * comparison. Derived fields may be ignored. The same fields, in the same
+ * order, should be used in both <code>compareTo(Object)</code> and
+ * <code>equals(Object)</code>.</p>
+ *
+ * <p>To use this class write code as follows:</p>
+ *
+ * <pre>
+ * public class MyClass {
+ *   String field1;
+ *   int field2;
+ *   boolean field3;
+ *
+ *   ...
+ *
+ *   public int compareTo(Object o) {
+ *     MyClass myClass = (MyClass) o;
+ *     return new CompareToBuilder()
+ *       .appendSuper(super.compareTo(o)
+ *       .append(this.field1, myClass.field1)
+ *       .append(this.field2, myClass.field2)
+ *       .append(this.field3, myClass.field3)
+ *       .toComparison();
+ *   }
+ * }
+ * </pre>
+ *
+ * <p>Alternatively, there is are {@link #reflectionCompare reflectionCompare} method that uses
+ * reflection to determine the fields to append. Because fields can be private,
+ * <code>reflectionCompare</code> uses {@link java.lang.reflect.AccessibleObject#setAccessible(boolean)} to
+ * bypass normal access control checks. This will fail under a security manager,
+ * unless the appropriate permissions are set up correctly. It is also
+ * slower than appending explicitly.</p>
+ *
+ * <p>A typical implementation of <code>compareTo(Object)</code> using
+ * <code>reflectionCompare</code> looks like:</p>
+
+ * <pre>
+ * public int compareTo(Object o) {
+ *   return CompareToBuilder.reflectionCompare(this, o);
+ * }
+ * </pre>
+ *
+ * @see java.lang.Comparable
+ * @see java.lang.Object#equals(Object)
+ * @see java.lang.Object#hashCode()
+ * @see EqualsBuilder
+ * @see HashCodeBuilder
+ * @author <a href="mailto:steve.downey@netfolio.com">Steve Downey</a>
+ * @author Stephen Colebourne
+ * @author Gary Gregory
+ * @author Pete Gieser
+ * @since 1.0
+ * @version $Id$
+ */
+public class CompareToBuilder {
+    
+    /**
+     * Current state of the comparison as appended fields are checked.
+     */
+    private int comparison;
+
+    /**
+     * <p>Constructor for CompareToBuilder.</p>
+     *
+     * <p>Starts off assuming that the objects are equal. Multiple calls are 
+     * then made to the various append methods, followed by a call to 
+     * {@link #toComparison} to get the result.</p>
+     */
+    public CompareToBuilder() {
+        super();
+        comparison = 0;
+    }
+
+    //-----------------------------------------------------------------------
+    /** 
+     * <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>Transient members will be not be compared, as they are likely derived
+     *     fields</li>
+     * <li>Superclass fields will be compared</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
+     * @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 (but not both) parameters are
+     *  <code>null</code>
+     * @throws ClassCastException  if <code>rhs</code> is not assignment-compatible
+     *  with <code>lhs</code>
+     */
+    public static int reflectionCompare(Object lhs, Object rhs) {
+        return reflectionCompare(lhs, rhs, false, 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 <code>compareTransients</code> is <code>true</code>,
+     *     compares transient members.  Otherwise ignores them, as they
+     *     are likely derived fields.</li>
+     * <li>Superclass fields will be compared</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
+     * @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>
+     */
+    public static int reflectionCompare(Object lhs, Object rhs, boolean compareTransients) {
+        return reflectionCompare(lhs, rhs, compareTransients, 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
+     * @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) {
+        if (lhs == rhs) {
+            return 0;
+        }
+        if (lhs == null || rhs == null) {
+            throw new NullPointerException();
+        }
+        Class lhsClazz = lhs.getClass();
+        if (!lhsClazz.isInstance(rhs)) {
+            throw new ClassCastException();
+        }
+        CompareToBuilder compareToBuilder = new CompareToBuilder();
+        reflectionAppend(lhs, rhs, lhsClazz, compareToBuilder, compareTransients);
+        while (lhsClazz.getSuperclass() != null && lhsClazz != reflectUpToClass) {
+            lhsClazz = lhsClazz.getSuperclass();
+            reflectionAppend(lhs, rhs, lhsClazz, compareToBuilder, compareTransients);
+        }
+        return compareToBuilder.toComparison();
+    }
+
+    /**
+     * <p>Appends to <code>builder</code> the comparison of <code>lhs</code>
+     * to <code>rhs</code> using the fields defined in <code>clazz</code>.</p>
+     * 
+     * @param lhs  left-hand object
+     * @param rhs  right-hand object
+     * @param clazz  <code>Class</code> that defines fields to be compared
+     * @param builder  <code>CompareToBuilder</code> to append to
+     * @param useTransients  whether to compare transient fields
+     */
+    private static void reflectionAppend(
+        Object lhs,
+        Object rhs,
+        Class clazz,
+        CompareToBuilder builder,
+        boolean useTransients) {
+        
+        Field[] fields = clazz.getDeclaredFields();
+        AccessibleObject.setAccessible(fields, true);
+        for (int i = 0; i < fields.length && builder.comparison == 0; i++) {
+            Field f = fields[i];
+            if ((f.getName().indexOf('$') == -1)
+                && (useTransients || !Modifier.isTransient(f.getModifiers()))
+                && (!Modifier.isStatic(f.getModifiers()))) {
+                try {
+                    builder.append(f.get(lhs), f.get(rhs));
+                } catch (IllegalAccessException e) {
+                    // This can't happen. Would get a Security exception instead.
+                    // Throw a runtime exception in case the impossible happens.
+                    throw new InternalError("Unexpected IllegalAccessException");
+                }
+            }
+        }
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Appends to the <code>builder</code> the <code>compareTo(Object)</code>
+     * result of the superclass.</p>
+     *
+     * @param superCompareTo  result of calling <code>super.compareTo(Object)</code>
+     * @return this - used to chain append calls
+     * @since 2.0
+     */
+    public CompareToBuilder appendSuper(int superCompareTo) {
+        if (comparison != 0) {
+            return this;
+        }
+        comparison = superCompareTo;
+        return this;
+    }
+    
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Appends to the <code>builder</code> the comparison of
+     * two <code>Object</code>s.</p>
+     *
+     * <ol>
+     * <li>Check if <code>lhs == rhs</code></li>
+     * <li>Check if either <code>lhs</code> or <code>rhs</code> is <code>null</code>,
+     *     a <code>null</code> object is less than a non-<code>null</code> object</li>
+     * <li>Check the object contents</li>
+     * </ol>
+     * 
+     * <p><code>lhs</code> must either be an array or implement {@link Comparable}.</p>
+     *
+     * @param lhs  left-hand object
+     * @param rhs  right-hand object
+     * @return this - used to chain append calls
+     * @throws ClassCastException  if <code>rhs</code> is not assignment-compatible
+     *  with <code>lhs</code>
+     */
+    public CompareToBuilder append(Object lhs, Object rhs) {
+        return append(lhs, rhs, null);
+    }
+
+    /**
+     * <p>Appends to the <code>builder</code> the comparison of
+     * two <code>Object</code>s.</p>
+     *
+     * <ol>
+     * <li>Check if <code>lhs == rhs</code></li>
+     * <li>Check if either <code>lhs</code> or <code>rhs</code> is <code>null</code>,
+     *     a <code>null</code> object is less than a non-<code>null</code> object</li>
+     * <li>Check the object contents</li>
+     * </ol>
+     *
+     * <p>If <code>lhs</code> is an array, array comparison methods will be used.
+     * Otherwise <code>comparator</code> will be used to compare the objects.
+     * If <code>comparator</code> is <code>null</code>, <code>lhs</code> must
+     * implement {@link Comparable} instead.</p>
+     *
+     * @param lhs  left-hand object
+     * @param rhs  right-hand object
+     * @param comparator  <code>Comparator</code> used to compare the objects,
+     *  <code>null</code> means treat lhs as <code>Comparable</code>
+     * @return this - used to chain append calls
+     * @throws ClassCastException  if <code>rhs</code> is not assignment-compatible
+     *  with <code>lhs</code>
+     * @since 2.0
+     */
+    public CompareToBuilder append(Object lhs, Object rhs, Comparator comparator) {
+        if (comparison != 0) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null) {
+            comparison = -1;
+            return this;
+        }
+        if (rhs == null) {
+            comparison = +1;
+            return this;
+        }
+        if (lhs.getClass().isArray()) {
+            // switch on type of array, to dispatch to the correct handler
+            // handles multi dimensional arrays
+            // throws a ClassCastException if rhs is not the correct array type
+            if (lhs instanceof long[]) {
+                append((long[]) lhs, (long[]) rhs);
+            } else if (lhs instanceof int[]) {
+                append((int[]) lhs, (int[]) rhs);
+            } else if (lhs instanceof short[]) {
+                append((short[]) lhs, (short[]) rhs);
+            } else if (lhs instanceof char[]) {
+                append((char[]) lhs, (char[]) rhs);
+            } else if (lhs instanceof byte[]) {
+                append((byte[]) lhs, (byte[]) rhs);
+            } else if (lhs instanceof double[]) {
+                append((double[]) lhs, (double[]) rhs);
+            } else if (lhs instanceof float[]) {
+                append((float[]) lhs, (float[]) rhs);
+            } else if (lhs instanceof boolean[]) {
+                append((boolean[]) lhs, (boolean[]) rhs);
+            } else {
+                // not an array of primitives
+                // throws a ClassCastException if rhs is not an array
+                append((Object[]) lhs, (Object[]) rhs, comparator);
+            }
+        } else {
+            // the simple case, not an array, just test the element
+            if (comparator == null) {
+                comparison = ((Comparable) lhs).compareTo(rhs);
+            } else {
+                comparison = comparator.compare(lhs, rhs);
+            }
+        }
+        return this;
+    }
+
+    //-------------------------------------------------------------------------
+    /**
+     * Appends to the <code>builder</code> the comparison of
+     * two <code>long</code>s.
+     *
+     * @param lhs  left-hand value
+     * @param rhs  right-hand value
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(long lhs, long rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
+        return this;
+    }
+
+    /**
+     * Appends to the <code>builder</code> the comparison of
+     * two <code>int</code>s.
+     *
+     * @param lhs  left-hand value
+     * @param rhs  right-hand value
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(int lhs, int rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
+        return this;
+    }
+
+    /**
+     * Appends to the <code>builder</code> the comparison of
+     * two <code>short</code>s.
+     * 
+     * @param lhs  left-hand value
+     * @param rhs  right-hand value
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(short lhs, short rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
+        return this;
+    }
+
+    /**
+     * Appends to the <code>builder</code> the comparison of
+     * two <code>char</code>s.
+     *
+     * @param lhs  left-hand value
+     * @param rhs  right-hand value
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(char lhs, char rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
+        return this;
+    }
+
+    /**
+     * Appends to the <code>builder</code> the comparison of
+     * two <code>byte</code>s.
+     * 
+     * @param lhs  left-hand value
+     * @param rhs  right-hand value
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(byte lhs, byte rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        comparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
+        return this;
+    }
+
+    /**
+     * <p>Appends to the <code>builder</code> the comparison of
+     * two <code>double</code>s.</p>
+     *
+     * <p>This handles NaNs, Infinities, and <code>-0.0</code>.</p>
+     *
+     * <p>It is compatible with the hash code generated by
+     * <code>HashCodeBuilder</code>.</p>
+     *
+     * @param lhs  left-hand value
+     * @param rhs  right-hand value
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(double lhs, double rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        comparison = NumberUtils.compare(lhs, rhs);
+        return this;
+    }
+
+    /**
+     * <p>Appends to the <code>builder</code> the comparison of
+     * two <code>float</code>s.</p>
+     *
+     * <p>This handles NaNs, Infinities, and <code>-0.0</code>.</p>
+     *
+     * <p>It is compatible with the hash code generated by
+     * <code>HashCodeBuilder</code>.</p>
+     *
+     * @param lhs  left-hand value
+     * @param rhs  right-hand value
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(float lhs, float rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        comparison = NumberUtils.compare(lhs, rhs);
+        return this;
+    }
+
+    /**
+     * Appends to the <code>builder</code> the comparison of
+     * two <code>booleans</code>s.
+     *
+     * @param lhs  left-hand value
+     * @param rhs  right-hand value
+     * @return this - used to chain append calls
+      */
+    public CompareToBuilder append(boolean lhs, boolean rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == false) {
+            comparison = -1;
+        } else {
+            comparison = +1;
+        }
+        return this;
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * <p>Appends to the <code>builder</code> the deep comparison of
+     * two <code>Object</code> arrays.</p>
+     *
+     * <ol>
+     *  <li>Check if arrays are the same using <code>==</code></li>
+     *  <li>Check if for <code>null</code>, <code>null</code> is less than non-<code>null</code></li>
+     *  <li>Check array length, a short length array is less than a long length array</li>
+     *  <li>Check array contents element by element using {@link #append(Object, Object, Comparator)}</li>
+     * </ol>
+     *
+     * <p>This method will also will be called for the top level of multi-dimensional,
+     * ragged, and multi-typed arrays.</p>
+     *
+     * @param lhs  left-hand array
+     * @param rhs  right-hand array
+     * @return this - used to chain append calls
+     * @throws ClassCastException  if <code>rhs</code> is not assignment-compatible
+     *  with <code>lhs</code>
+     */
+    public CompareToBuilder append(Object[] lhs, Object[] rhs) {
+        return append(lhs, rhs, null);
+    }
+    
+    /**
+     * <p>Appends to the <code>builder</code> the deep comparison of
+     * two <code>Object</code> arrays.</p>
+     *
+     * <ol>
+     *  <li>Check if arrays are the same using <code>==</code></li>
+     *  <li>Check if for <code>null</code>, <code>null</code> is less than non-<code>null</code></li>
+     *  <li>Check array length, a short length array is less than a long length array</li>
+     *  <li>Check array contents element by element using {@link #append(Object, Object, Comparator)}</li>
+     * </ol>
+     *
+     * <p>This method will also will be called for the top level of multi-dimensional,
+     * ragged, and multi-typed arrays.</p>
+     *
+     * @param lhs  left-hand array
+     * @param rhs  right-hand array
+     * @param comparator  <code>Comparator</code> to use to compare the array elements,
+     *  <code>null</code> means to treat <code>lhs</code> elements as <code>Comparable</code>.
+     * @return this - used to chain append calls
+     * @throws ClassCastException  if <code>rhs</code> is not assignment-compatible
+     *  with <code>lhs</code>
+     * @since 2.0
+     */
+    public CompareToBuilder append(Object[] lhs, Object[] rhs, Comparator comparator) {
+        if (comparison != 0) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null) {
+            comparison = -1;
+            return this;
+        }
+        if (rhs == null) {
+            comparison = +1;
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            return this;
+        }
+        for (int i = 0; i < lhs.length && comparison == 0; i++) {
+            append(lhs[i], rhs[i], comparator);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Appends to the <code>builder</code> the deep comparison of
+     * two <code>long</code> arrays.</p>
+     *
+     * <ol>
+     *  <li>Check if arrays are the same using <code>==</code></li>
+     *  <li>Check if for <code>null</code>, <code>null</code> is less than non-<code>null</code></li>
+     *  <li>Check array length, a shorter length array is less than a longer length array</li>
+     *  <li>Check array contents element by element using {@link #append(long, long)}</li>
+     * </ol>
+     *
+     * @param lhs  left-hand array
+     * @param rhs  right-hand array
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(long[] lhs, long[] rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null) {
+            comparison = -1;
+            return this;
+        }
+        if (rhs == null) {
+            comparison = +1;
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            return this;
+        }
+        for (int i = 0; i < lhs.length && comparison == 0; i++) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Appends to the <code>builder</code> the deep comparison of
+     * two <code>int</code> arrays.</p>
+     *
+     * <ol>
+     *  <li>Check if arrays are the same using <code>==</code></li>
+     *  <li>Check if for <code>null</code>, <code>null</code> is less than non-<code>null</code></li>
+     *  <li>Check array length, a shorter length array is less than a longer length array</li>
+     *  <li>Check array contents element by element using {@link #append(int, int)}</li>
+     * </ol>
+     *
+     * @param lhs  left-hand array
+     * @param rhs  right-hand array
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(int[] lhs, int[] rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null) {
+            comparison = -1;
+            return this;
+        }
+        if (rhs == null) {
+            comparison = +1;
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            return this;
+        }
+        for (int i = 0; i < lhs.length && comparison == 0; i++) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Appends to the <code>builder</code> the deep comparison of
+     * two <code>short</code> arrays.</p>
+     *
+     * <ol>
+     *  <li>Check if arrays are the same using <code>==</code></li>
+     *  <li>Check if for <code>null</code>, <code>null</code> is less than non-<code>null</code></li>
+     *  <li>Check array length, a shorter length array is less than a longer length array</li>
+     *  <li>Check array contents element by element using {@link #append(short, short)}</li>
+     * </ol>
+     *
+     * @param lhs  left-hand array
+     * @param rhs  right-hand array
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(short[] lhs, short[] rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null) {
+            comparison = -1;
+            return this;
+        }
+        if (rhs == null) {
+            comparison = +1;
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            return this;
+        }
+        for (int i = 0; i < lhs.length && comparison == 0; i++) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Appends to the <code>builder</code> the deep comparison of
+     * two <code>char</code> arrays.</p>
+     *
+     * <ol>
+     *  <li>Check if arrays are the same using <code>==</code></li>
+     *  <li>Check if for <code>null</code>, <code>null</code> is less than non-<code>null</code></li>
+     *  <li>Check array length, a shorter length array is less than a longer length array</li>
+     *  <li>Check array contents element by element using {@link #append(char, char)}</li>
+     * </ol>
+     *
+     * @param lhs  left-hand array
+     * @param rhs  right-hand array
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(char[] lhs, char[] rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null) {
+            comparison = -1;
+            return this;
+        }
+        if (rhs == null) {
+            comparison = +1;
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            return this;
+        }
+        for (int i = 0; i < lhs.length && comparison == 0; i++) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Appends to the <code>builder</code> the deep comparison of
+     * two <code>byte</code> arrays.</p>
+     *
+     * <ol>
+     *  <li>Check if arrays are the same using <code>==</code></li>
+     *  <li>Check if for <code>null</code>, <code>null</code> is less than non-<code>null</code></li>
+     *  <li>Check array length, a shorter length array is less than a longer length array</li>
+     *  <li>Check array contents element by element using {@link #append(byte, byte)}</li>
+     * </ol>
+     *
+     * @param lhs  left-hand array
+     * @param rhs  right-hand array
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(byte[] lhs, byte[] rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null) {
+            comparison = -1;
+            return this;
+        }
+        if (rhs == null) {
+            comparison = +1;
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            return this;
+        }
+        for (int i = 0; i < lhs.length && comparison == 0; i++) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Appends to the <code>builder</code> the deep comparison of
+     * two <code>double</code> arrays.</p>
+     *
+     * <ol>
+     *  <li>Check if arrays are the same using <code>==</code></li>
+     *  <li>Check if for <code>null</code>, <code>null</code> is less than non-<code>null</code></li>
+     *  <li>Check array length, a shorter length array is less than a longer length array</li>
+     *  <li>Check array contents element by element using {@link #append(double, double)}</li>
+     * </ol>
+     *
+     * @param lhs  left-hand array
+     * @param rhs  right-hand array
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(double[] lhs, double[] rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null) {
+            comparison = -1;
+            return this;
+        }
+        if (rhs == null) {
+            comparison = +1;
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            return this;
+        }
+        for (int i = 0; i < lhs.length && comparison == 0; i++) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Appends to the <code>builder</code> the deep comparison of
+     * two <code>float</code> arrays.</p>
+     *
+     * <ol>
+     *  <li>Check if arrays are the same using <code>==</code></li>
+     *  <li>Check if for <code>null</code>, <code>null</code> is less than non-<code>null</code></li>
+     *  <li>Check array length, a shorter length array is less than a longer length array</li>
+     *  <li>Check array contents element by element using {@link #append(float, float)}</li>
+     * </ol>
+     *
+     * @param lhs  left-hand array
+     * @param rhs  right-hand array
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(float[] lhs, float[] rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null) {
+            comparison = -1;
+            return this;
+        }
+        if (rhs == null) {
+            comparison = +1;
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            return this;
+        }
+        for (int i = 0; i < lhs.length && comparison == 0; i++) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Appends to the <code>builder</code> the deep comparison of
+     * two <code>boolean</code> arrays.</p>
+     *
+     * <ol>
+     *  <li>Check if arrays are the same using <code>==</code></li>
+     *  <li>Check if for <code>null</code>, <code>null</code> is less than non-<code>null</code></li>
+     *  <li>Check array length, a shorter length array is less than a longer length array</li>
+     *  <li>Check array contents element by element using {@link #append(boolean, boolean)}</li>
+     * </ol>
+     *
+     * @param lhs  left-hand array
+     * @param rhs  right-hand array
+     * @return this - used to chain append calls
+     */
+    public CompareToBuilder append(boolean[] lhs, boolean[] rhs) {
+        if (comparison != 0) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null) {
+            comparison = -1;
+            return this;
+        }
+        if (rhs == null) {
+            comparison = +1;
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            comparison = (lhs.length < rhs.length) ? -1 : +1;
+            return this;
+        }
+        for (int i = 0; i < lhs.length && comparison == 0; i++) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Returns a negative integer, a positive integer, or zero as
+     * the <code>builder</code> has judged the "left-hand" side
+     * as less than, greater than, or equal to the "right-hand"
+     * side.
+     * 
+     * @return final comparison result
+     */
+    public int toComparison() {
+        return comparison;
+    }
+
+}
+

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/builder/CompareToBuilder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision

Added: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/builder/EqualsBuilder.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/builder/EqualsBuilder.java?rev=370807&view=auto
==============================================================================
--- directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/builder/EqualsBuilder.java (added)
+++ directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/builder/EqualsBuilder.java Fri Jan 20 05:47:50 2006
@@ -0,0 +1,758 @@
+/*
+ * Copyright 2002-2005 The Apache Software Foundation.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.mina.common.support.lang.builder;
+
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+
+/**
+ * <p>Assists in implementing {@link Object#equals(Object)} methods.</p>
+ *
+ * <p> This class provides methods to build a good equals method for any
+ * class. It follows rules laid out in
+ * <a href="http://java.sun.com/docs/books/effective/index.html">Effective Java</a>
+ * , by Joshua Bloch. In particular the rule for comparing <code>doubles</code>,
+ * <code>floats</code>, and arrays can be tricky. Also, making sure that
+ * <code>equals()</code> and <code>hashCode()</code> are consistent can be
+ * difficult.</p>
+ *
+ * <p>Two Objects that compare as equals must generate the same hash code,
+ * but two Objects with the same hash code do not have to be equal.</p>
+ *
+ * <p>All relevant fields should be included in the calculation of equals.
+ * Derived fields may be ignored. In particular, any field used in
+ * generating a hash code must be used in the equals method, and vice
+ * versa.</p>
+ *
+ * <p>Typical use for the code is as follows:</p>
+ * <pre>
+ * public boolean equals(Object obj) {
+ *   if (obj instanceof MyClass == false) {
+ *     return false;
+ *   }
+ *   if (this == obj) {
+ *     return true;
+ *   }
+ *   MyClass rhs = (MyClass) obj;
+ *   return new EqualsBuilder()
+ *                 .appendSuper(super.equals(obj))
+ *                 .append(field1, rhs.field1)
+ *                 .append(field2, rhs.field2)
+ *                 .append(field3, rhs.field3)
+ *                 .isEquals();
+ *  }
+ * </pre>
+ *
+ * <p> Alternatively, there is a method that uses reflection to determine
+ * the fields to test. Because these fields are usually private, the method,
+ * <code>reflectionEquals</code>, uses <code>AccessibleObject.setAccessible</code> to
+ * 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 equals(Object obj) {
+ *   return EqualsBuilder.reflectionEquals(this, obj);
+ * }
+ * </pre>
+ *
+ * @author <a href="mailto:steve.downey@netfolio.com">Steve Downey</a>
+ * @author Stephen Colebourne
+ * @author Gary Gregory
+ * @author Pete Gieser
+ * @author Arun Mammen Thomas
+ * @since 1.0
+ * @version $Id$
+ */
+public class EqualsBuilder {
+    
+    /**
+     * If the fields tested are equals.
+     * The default value is <code>true</code>.
+     */
+    private boolean isEquals = true;
+
+    /**
+     * <p>Constructor for EqualsBuilder.</p>
+     *
+     * <p>Starts off assuming that equals is <code>true</code>.</p>
+     * @see Object#equals(Object)
+     */
+    public EqualsBuilder() {
+        // do nothing for now.
+    }
+
+    //-------------------------------------------------------------------------
+
+    /**
+     * <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);
+    }
+
+    /**
+     * <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 tested. Superclass fields will be included.</p>
+     *
+     * @param lhs  <code>this</code> object
+     * @param rhs  the other object
+     * @param testTransients  whether to include transient fields
+     * @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);
+    }
+
+    /**
+     * <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) {
+        if (lhs == rhs) {
+            return true;
+        }
+        if (lhs == null || rhs == null) {
+            return false;
+        }
+        // Find the leaf class since there may be transients in the leaf 
+        // class or in classes between the leaf and root.
+        // If we are not testing transients or a subclass has no ivars, 
+        // then a subclass can test equals to a superclass.
+        Class lhsClass = lhs.getClass();
+        Class rhsClass = rhs.getClass();
+        Class testClass;
+        if (lhsClass.isInstance(rhs)) {
+            testClass = lhsClass;
+            if (!rhsClass.isInstance(lhs)) {
+                // rhsClass is a subclass of lhsClass
+                testClass = rhsClass;
+            }
+        } else if (rhsClass.isInstance(lhs)) {
+            testClass = rhsClass;
+            if (!lhsClass.isInstance(rhs)) {
+                // lhsClass is a subclass of rhsClass
+                testClass = lhsClass;
+            }
+        } else {
+            // The two classes are not related.
+            return false;
+        }
+        EqualsBuilder equalsBuilder = new EqualsBuilder();
+        try {
+            reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients);
+            while (testClass.getSuperclass() != null && testClass != reflectUpToClass) {
+                testClass = testClass.getSuperclass();
+                reflectionAppend(lhs, rhs, testClass, equalsBuilder, testTransients);
+            }
+        } catch (IllegalArgumentException e) {
+            // In this case, we tried to test a subclass vs. a superclass and
+            // the subclass has ivars or the ivars are transient and 
+            // we are testing transients.
+            // If a subclass has ivars that we are trying to test them, we get an
+            // exception and we know that the objects are not equal.
+            return false;
+        }
+        return equalsBuilder.isEquals();
+    }
+
+    /**
+     * <p>Appends the fields and values defined by the given object of the
+     * given Class.</p>
+     * 
+     * @param lhs  the left hand object
+     * @param rhs  the right hand object
+     * @param clazz  the class to append details of
+     * @param builder  the builder to append to
+     * @param useTransients  whether to test transient fields
+     */
+    private static void reflectionAppend(
+        Object lhs,
+        Object rhs,
+        Class clazz,
+        EqualsBuilder builder,
+        boolean useTransients) {
+        Field[] fields = clazz.getDeclaredFields();
+        AccessibleObject.setAccessible(fields, true);
+        for (int i = 0; i < fields.length && builder.isEquals; i++) {
+            Field f = fields[i];
+            if ((f.getName().indexOf('$') == -1)
+                && (useTransients || !Modifier.isTransient(f.getModifiers()))
+                && (!Modifier.isStatic(f.getModifiers()))) {
+                try {
+                    builder.append(f.get(lhs), f.get(rhs));
+                } catch (IllegalAccessException e) {
+                    //this can't happen. Would get a Security exception instead
+                    //throw a runtime exception in case the impossible happens.
+                    throw new InternalError("Unexpected IllegalAccessException");
+                }
+            }
+        }
+    }
+
+    //-------------------------------------------------------------------------
+
+    /**
+     * <p>Adds the result of <code>super.equals()</code> to this builder.</p>
+     *
+     * @param superEquals  the result of calling <code>super.equals()</code>
+     * @return EqualsBuilder - used to chain calls.
+     * @since 2.0
+     */
+    public EqualsBuilder appendSuper(boolean superEquals) {
+        if (isEquals == false) {
+            return this;
+        }
+        isEquals = superEquals;
+        return this;
+    }
+
+    //-------------------------------------------------------------------------
+
+    /**
+     * <p>Test if two <code>Object</code>s are equal using their
+     * <code>equals</code> method.</p>
+     *
+     * @param lhs  the left hand object
+     * @param rhs  the right hand object
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(Object lhs, Object rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null || rhs == null) {
+            this.setEquals(false);
+            return this;
+        }
+        Class lhsClass = lhs.getClass();
+        if (!lhsClass.isArray()) {
+            // The simple case, not an array, just test the element
+            isEquals = lhs.equals(rhs);
+        } else if (lhs.getClass() != rhs.getClass()) {
+            // Here when we compare different dimensions, for example: a boolean[][] to a boolean[] 
+            this.setEquals(false);
+        }
+        // 'Switch' on type of array, to dispatch to the correct handler
+        // This handles multi dimensional arrays of the same depth
+        else if (lhs instanceof long[]) {
+            append((long[]) lhs, (long[]) rhs);
+        } else if (lhs instanceof int[]) {
+            append((int[]) lhs, (int[]) rhs);
+        } else if (lhs instanceof short[]) {
+            append((short[]) lhs, (short[]) rhs);
+        } else if (lhs instanceof char[]) {
+            append((char[]) lhs, (char[]) rhs);
+        } else if (lhs instanceof byte[]) {
+            append((byte[]) lhs, (byte[]) rhs);
+        } else if (lhs instanceof double[]) {
+            append((double[]) lhs, (double[]) rhs);
+        } else if (lhs instanceof float[]) {
+            append((float[]) lhs, (float[]) rhs);
+        } else if (lhs instanceof boolean[]) {
+            append((boolean[]) lhs, (boolean[]) rhs);
+        } else {
+            // Not an array of primitives
+            append((Object[]) lhs, (Object[]) rhs);
+        }
+        return this;
+    }
+
+    /**
+     * <p>
+     * Test if two <code>long</code> s are equal.
+     * </p>
+     * 
+     * @param lhs
+     *                  the left hand <code>long</code>
+     * @param rhs
+     *                  the right hand <code>long</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(long lhs, long rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        isEquals = (lhs == rhs);
+        return this;
+    }
+
+    /**
+     * <p>Test if two <code>int</code>s are equal.</p>
+     *
+     * @param lhs  the left hand <code>int</code>
+     * @param rhs  the right hand <code>int</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(int lhs, int rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        isEquals = (lhs == rhs);
+        return this;
+    }
+
+    /**
+     * <p>Test if two <code>short</code>s are equal.</p>
+     *
+     * @param lhs  the left hand <code>short</code>
+     * @param rhs  the right hand <code>short</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(short lhs, short rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        isEquals = (lhs == rhs);
+        return this;
+    }
+
+    /**
+     * <p>Test if two <code>char</code>s are equal.</p>
+     *
+     * @param lhs  the left hand <code>char</code>
+     * @param rhs  the right hand <code>char</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(char lhs, char rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        isEquals = (lhs == rhs);
+        return this;
+    }
+
+    /**
+     * <p>Test if two <code>byte</code>s are equal.</p>
+     *
+     * @param lhs  the left hand <code>byte</code>
+     * @param rhs  the right hand <code>byte</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(byte lhs, byte rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        isEquals = (lhs == rhs);
+        return this;
+    }
+
+    /**
+     * <p>Test if two <code>double</code>s are equal by testing that the
+     * pattern of bits returned by <code>doubleToLong</code> are equal.</p>
+     *
+     * <p>This handles NaNs, Infinities, and <code>-0.0</code>.</p>
+     *
+     * <p>It is compatible with the hash code generated by
+     * <code>HashCodeBuilder</code>.</p>
+     *
+     * @param lhs  the left hand <code>double</code>
+     * @param rhs  the right hand <code>double</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(double lhs, double rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        return append(Double.doubleToLongBits(lhs), Double.doubleToLongBits(rhs));
+    }
+
+    /**
+     * <p>Test if two <code>float</code>s are equal byt testing that the
+     * pattern of bits returned by doubleToLong are equal.</p>
+     *
+     * <p>This handles NaNs, Infinities, and <code>-0.0</code>.</p>
+     *
+     * <p>It is compatible with the hash code generated by
+     * <code>HashCodeBuilder</code>.</p>
+     *
+     * @param lhs  the left hand <code>float</code>
+     * @param rhs  the right hand <code>float</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(float lhs, float rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        return append(Float.floatToIntBits(lhs), Float.floatToIntBits(rhs));
+    }
+
+    /**
+     * <p>Test if two <code>booleans</code>s are equal.</p>
+     *
+     * @param lhs  the left hand <code>boolean</code>
+     * @param rhs  the right hand <code>boolean</code>
+     * @return EqualsBuilder - used to chain calls.
+      */
+    public EqualsBuilder append(boolean lhs, boolean rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        isEquals = (lhs == rhs);
+        return this;
+    }
+
+    /**
+     * <p>Performs a deep comparison of two <code>Object</code> arrays.</p>
+     *
+     * <p>This also will be called for the top level of
+     * multi-dimensional, ragged, and multi-typed arrays.</p>
+     *
+     * @param lhs  the left hand <code>Object[]</code>
+     * @param rhs  the right hand <code>Object[]</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(Object[] lhs, Object[] rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null || rhs == null) {
+            this.setEquals(false);
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            this.setEquals(false);
+            return this;
+        }
+        for (int i = 0; i < lhs.length && isEquals; ++i) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Deep comparison of array of <code>long</code>. Length and all
+     * values are compared.</p>
+     *
+     * <p>The method {@link #append(long, long)} is used.</p>
+     *
+     * @param lhs  the left hand <code>long[]</code>
+     * @param rhs  the right hand <code>long[]</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(long[] lhs, long[] rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null || rhs == null) {
+            this.setEquals(false);
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            this.setEquals(false);
+            return this;
+        }
+        for (int i = 0; i < lhs.length && isEquals; ++i) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Deep comparison of array of <code>int</code>. Length and all
+     * values are compared.</p>
+     *
+     * <p>The method {@link #append(int, int)} is used.</p>
+     *
+     * @param lhs  the left hand <code>int[]</code>
+     * @param rhs  the right hand <code>int[]</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(int[] lhs, int[] rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null || rhs == null) {
+            this.setEquals(false);
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            this.setEquals(false);
+            return this;
+        }
+        for (int i = 0; i < lhs.length && isEquals; ++i) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Deep comparison of array of <code>short</code>. Length and all
+     * values are compared.</p>
+     *
+     * <p>The method {@link #append(short, short)} is used.</p>
+     *
+     * @param lhs  the left hand <code>short[]</code>
+     * @param rhs  the right hand <code>short[]</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(short[] lhs, short[] rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null || rhs == null) {
+            this.setEquals(false);
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            this.setEquals(false);
+            return this;
+        }
+        for (int i = 0; i < lhs.length && isEquals; ++i) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Deep comparison of array of <code>char</code>. Length and all
+     * values are compared.</p>
+     *
+     * <p>The method {@link #append(char, char)} is used.</p>
+     *
+     * @param lhs  the left hand <code>char[]</code>
+     * @param rhs  the right hand <code>char[]</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(char[] lhs, char[] rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null || rhs == null) {
+            this.setEquals(false);
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            this.setEquals(false);
+            return this;
+        }
+        for (int i = 0; i < lhs.length && isEquals; ++i) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Deep comparison of array of <code>byte</code>. Length and all
+     * values are compared.</p>
+     *
+     * <p>The method {@link #append(byte, byte)} is used.</p>
+     *
+     * @param lhs  the left hand <code>byte[]</code>
+     * @param rhs  the right hand <code>byte[]</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(byte[] lhs, byte[] rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null || rhs == null) {
+            this.setEquals(false);
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            this.setEquals(false);
+            return this;
+        }
+        for (int i = 0; i < lhs.length && isEquals; ++i) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Deep comparison of array of <code>double</code>. Length and all
+     * values are compared.</p>
+     *
+     * <p>The method {@link #append(double, double)} is used.</p>
+     *
+     * @param lhs  the left hand <code>double[]</code>
+     * @param rhs  the right hand <code>double[]</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(double[] lhs, double[] rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null || rhs == null) {
+            this.setEquals(false);
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            this.setEquals(false);
+            return this;
+        }
+        for (int i = 0; i < lhs.length && isEquals; ++i) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Deep comparison of array of <code>float</code>. Length and all
+     * values are compared.</p>
+     *
+     * <p>The method {@link #append(float, float)} is used.</p>
+     *
+     * @param lhs  the left hand <code>float[]</code>
+     * @param rhs  the right hand <code>float[]</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(float[] lhs, float[] rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null || rhs == null) {
+            this.setEquals(false);
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            this.setEquals(false);
+            return this;
+        }
+        for (int i = 0; i < lhs.length && isEquals; ++i) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Deep comparison of array of <code>boolean</code>. Length and all
+     * values are compared.</p>
+     *
+     * <p>The method {@link #append(boolean, boolean)} is used.</p>
+     *
+     * @param lhs  the left hand <code>boolean[]</code>
+     * @param rhs  the right hand <code>boolean[]</code>
+     * @return EqualsBuilder - used to chain calls.
+     */
+    public EqualsBuilder append(boolean[] lhs, boolean[] rhs) {
+        if (isEquals == false) {
+            return this;
+        }
+        if (lhs == rhs) {
+            return this;
+        }
+        if (lhs == null || rhs == null) {
+            this.setEquals(false);
+            return this;
+        }
+        if (lhs.length != rhs.length) {
+            this.setEquals(false);
+            return this;
+        }
+        for (int i = 0; i < lhs.length && isEquals; ++i) {
+            append(lhs[i], rhs[i]);
+        }
+        return this;
+    }
+
+    /**
+     * <p>Returns <code>true</code> if the fields that have been checked
+     * are all equal.</p>
+     *
+     * @return boolean
+     */
+    public boolean isEquals() {
+        return this.isEquals;
+    }
+
+    /**
+     * Sets the <code>isEquals</code> value.
+     * 
+     * @param isEquals The value to set.
+     * @since 2.1
+     */
+    protected void setEquals(boolean isEquals) {
+        this.isEquals = isEquals;
+    }
+}

Propchange: directory/sandbox/trustin/mina-spi/core/src/main/java/org/apache/mina/common/support/lang/builder/EqualsBuilder.java
------------------------------------------------------------------------------
    svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision



Mime
View raw message