Class CompareToBuilder
public class CompareToBuilder extends Object
Comparable.compareTo(Object) methods.
 This code is based on CompareToBuilder from commons-lang v2.6- Since:
- 4.1
- 
Constructor SummaryConstructors Constructor Description CompareToBuilder()Constructor for CompareToBuilder.
- 
Method SummaryModifier and Type Method Description CompareToBuilderappend(boolean[] lhs, boolean[] rhs)Appends to thebuilderthe deep comparison of twobooleanarrays.CompareToBuilderappend(boolean lhs, boolean rhs)Appends to thebuilderthe comparison of twobooleanss.CompareToBuilderappend(byte[] lhs, byte[] rhs)Appends to thebuilderthe deep comparison of twobytearrays.CompareToBuilderappend(byte lhs, byte rhs)Appends to thebuilderthe comparison of twobytes.CompareToBuilderappend(char[] lhs, char[] rhs)Appends to thebuilderthe deep comparison of twochararrays.CompareToBuilderappend(char lhs, char rhs)Appends to thebuilderthe comparison of twochars.CompareToBuilderappend(double[] lhs, double[] rhs)Appends to thebuilderthe deep comparison of twodoublearrays.CompareToBuilderappend(double lhs, double rhs)Appends to thebuilderthe comparison of twodoubles.CompareToBuilderappend(float[] lhs, float[] rhs)Appends to thebuilderthe deep comparison of twofloatarrays.CompareToBuilderappend(float lhs, float rhs)Appends to thebuilderthe comparison of twofloats.CompareToBuilderappend(int[] lhs, int[] rhs)Appends to thebuilderthe deep comparison of twointarrays.CompareToBuilderappend(int lhs, int rhs)Appends to thebuilderthe comparison of twoints.CompareToBuilderappend(long[] lhs, long[] rhs)Appends to thebuilderthe deep comparison of twolongarrays.CompareToBuilderappend(long lhs, long rhs)Appends to thebuilderthe comparison of twolongs.CompareToBuilderappend(short[] lhs, short[] rhs)Appends to thebuilderthe deep comparison of twoshortarrays.CompareToBuilderappend(short lhs, short rhs)Appends to thebuilderthe comparison of twoshorts.CompareToBuilderappend(Object[] lhs, Object[] rhs)Appends to thebuilderthe deep comparison of twoObjectarrays.CompareToBuilderappend(Object[] lhs, Object[] rhs, Comparator comparator)Appends to thebuilderthe deep comparison of twoObjectarrays.CompareToBuilderappend(Object lhs, Object rhs)Appends to thebuilderthe comparison of twoObjects.CompareToBuilderappend(Object lhs, Object rhs, Comparator comparator)Appends to thebuilderthe comparison of twoObjects.CompareToBuilderappendSuper(int superCompareTo)Appends to thebuilderthecompareTo(Object)result of the superclass.inttoComparison()Returns a negative integer, a positive integer, or zero as thebuilderhas judged the "left-hand" side as less than, greater than, or equal to the "right-hand" side.
- 
Constructor Details- 
CompareToBuilderpublic CompareToBuilder()Constructor for CompareToBuilder. Starts off assuming that the objects are equal. Multiple calls are then made to the various append methods, followed by a call to toComparison()to get the result.
 
- 
- 
Method Details- 
appendSuperAppends to the builderthecompareTo(Object)result of the superclass.- Parameters:
- superCompareTo- result of calling- super.compareTo(Object)
- Returns:
- this - used to chain append calls
 
- 
appendAppends to the builderthe comparison of twoObjects.- Check if lhs == rhs
- Check if either lhsorrhsisnull, anullobject is less than a non-nullobject
- Check the object contents
 lhsmust either be an array or implementComparable.- Parameters:
- lhs- left-hand object
- rhs- right-hand object
- Returns:
- this - used to chain append calls
- Throws:
- ClassCastException- if- rhsis not assignment-compatible with- lhs
 
- Check if 
- 
appendAppends to the builderthe comparison of twoObjects.- Check if lhs == rhs
- Check if either lhsorrhsisnull, anullobject is less than a non-nullobject
- Check the object contents
 If lhsis an array, array comparison methods will be used. Otherwisecomparatorwill be used to compare the objects. Ifcomparatorisnull,lhsmust implementComparableinstead.- Parameters:
- lhs- left-hand object
- rhs- right-hand object
- comparator-- Comparatorused to compare the objects,- nullmeans treat lhs as- Comparable
- Returns:
- this - used to chain append calls
- Throws:
- ClassCastException- if- rhsis not assignment-compatible with- lhs
- Since:
- 2.0
 
- Check if 
- 
appendAppends to thebuilderthe comparison of twolongs.- Parameters:
- lhs- left-hand value
- rhs- right-hand value
- Returns:
- this - used to chain append calls
 
- 
appendAppends to thebuilderthe comparison of twoints.- Parameters:
- lhs- left-hand value
- rhs- right-hand value
- Returns:
- this - used to chain append calls
 
- 
appendAppends to thebuilderthe comparison of twoshorts.- Parameters:
- lhs- left-hand value
- rhs- right-hand value
- Returns:
- this - used to chain append calls
 
- 
appendAppends to thebuilderthe comparison of twochars.- Parameters:
- lhs- left-hand value
- rhs- right-hand value
- Returns:
- this - used to chain append calls
 
- 
appendAppends to thebuilderthe comparison of twobytes.- Parameters:
- lhs- left-hand value
- rhs- right-hand value
- Returns:
- this - used to chain append calls
 
- 
appendAppends to the builderthe comparison of twodoubles.This handles NaNs, Infinities, and -0.0.It is compatible with the hash code generated by HashCodeBuilder.- Parameters:
- lhs- left-hand value
- rhs- right-hand value
- Returns:
- this - used to chain append calls
 
- 
appendAppends to the builderthe comparison of twofloats.This handles NaNs, Infinities, and -0.0.It is compatible with the hash code generated by HashCodeBuilder.- Parameters:
- lhs- left-hand value
- rhs- right-hand value
- Returns:
- this - used to chain append calls
 
- 
appendAppends to thebuilderthe comparison of twobooleanss.- Parameters:
- lhs- left-hand value
- rhs- right-hand value
- Returns:
- this - used to chain append calls
 
- 
appendAppends to the builderthe deep comparison of twoObjectarrays.- Check if arrays are the same using ==
- Check if for null,nullis less than non-null
- Check array length, a short length array is less than a long length array
- Check array contents element by element using append(Object, Object, Comparator)
 This method will also will be called for the top level of multi-dimensional, ragged, and multi-typed arrays. - Parameters:
- lhs- left-hand array
- rhs- right-hand array
- Returns:
- this - used to chain append calls
- Throws:
- ClassCastException- if- rhsis not assignment-compatible with- lhs
 
- Check if arrays are the same using 
- 
appendAppends to the builderthe deep comparison of twoObjectarrays.- Check if arrays are the same using ==
- Check if for null,nullis less than non-null
- Check array length, a short length array is less than a long length array
- Check array contents element by element using append(Object, Object, Comparator)
 This method will also will be called for the top level of multi-dimensional, ragged, and multi-typed arrays. - Parameters:
- lhs- left-hand array
- rhs- right-hand array
- comparator-- Comparatorto use to compare the array elements,- nullmeans to treat- lhselements as- Comparable.
- Returns:
- this - used to chain append calls
- Throws:
- ClassCastException- if- rhsis not assignment-compatible with- lhs
- Since:
- 2.0
 
- Check if arrays are the same using 
- 
appendAppends to the builderthe deep comparison of twolongarrays.- Check if arrays are the same using ==
- Check if for null,nullis less than non-null
- Check array length, a shorter length array is less than a longer length array
- Check array contents element by element using append(long, long)
 - Parameters:
- lhs- left-hand array
- rhs- right-hand array
- Returns:
- this - used to chain append calls
 
- Check if arrays are the same using 
- 
appendAppends to the builderthe deep comparison of twointarrays.- Check if arrays are the same using ==
- Check if for null,nullis less than non-null
- Check array length, a shorter length array is less than a longer length array
- Check array contents element by element using append(int, int)
 - Parameters:
- lhs- left-hand array
- rhs- right-hand array
- Returns:
- this - used to chain append calls
 
- Check if arrays are the same using 
- 
appendAppends to the builderthe deep comparison of twoshortarrays.- Check if arrays are the same using ==
- Check if for null,nullis less than non-null
- Check array length, a shorter length array is less than a longer length array
- Check array contents element by element using append(short, short)
 - Parameters:
- lhs- left-hand array
- rhs- right-hand array
- Returns:
- this - used to chain append calls
 
- Check if arrays are the same using 
- 
appendAppends to the builderthe deep comparison of twochararrays.- Check if arrays are the same using ==
- Check if for null,nullis less than non-null
- Check array length, a shorter length array is less than a longer length array
- Check array contents element by element using append(char, char)
 - Parameters:
- lhs- left-hand array
- rhs- right-hand array
- Returns:
- this - used to chain append calls
 
- Check if arrays are the same using 
- 
appendAppends to the builderthe deep comparison of twobytearrays.- Check if arrays are the same using ==
- Check if for null,nullis less than non-null
- Check array length, a shorter length array is less than a longer length array
- Check array contents element by element using append(byte, byte)
 - Parameters:
- lhs- left-hand array
- rhs- right-hand array
- Returns:
- this - used to chain append calls
 
- Check if arrays are the same using 
- 
appendAppends to the builderthe deep comparison of twodoublearrays.- Check if arrays are the same using ==
- Check if for null,nullis less than non-null
- Check array length, a shorter length array is less than a longer length array
- Check array contents element by element using append(double, double)
 - Parameters:
- lhs- left-hand array
- rhs- right-hand array
- Returns:
- this - used to chain append calls
 
- Check if arrays are the same using 
- 
appendAppends to the builderthe deep comparison of twofloatarrays.- Check if arrays are the same using ==
- Check if for null,nullis less than non-null
- Check array length, a shorter length array is less than a longer length array
- Check array contents element by element using append(float, float)
 - Parameters:
- lhs- left-hand array
- rhs- right-hand array
- Returns:
- this - used to chain append calls
 
- Check if arrays are the same using 
- 
appendAppends to the builderthe deep comparison of twobooleanarrays.- Check if arrays are the same using ==
- Check if for null,nullis less than non-null
- Check array length, a shorter length array is less than a longer length array
- Check array contents element by element using append(boolean, boolean)
 - Parameters:
- lhs- left-hand array
- rhs- right-hand array
- Returns:
- this - used to chain append calls
 
- Check if arrays are the same using 
- 
toComparisonpublic int toComparison()Returns a negative integer, a positive integer, or zero as thebuilderhas judged the "left-hand" side as less than, greater than, or equal to the "right-hand" side.- Returns:
- final comparison result
 
 
-