Class CompareToBuilder
Comparable.compareTo(Object)
methods.
This code is based on CompareToBuilder from commons-lang v2.6- Since:
- 4.1
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionappend
(boolean[] lhs, boolean[] rhs) Appends to thebuilder
the deep comparison of twoboolean
arrays.append
(boolean lhs, boolean rhs) Appends to thebuilder
the comparison of twobooleans
s.append
(byte[] lhs, byte[] rhs) Appends to thebuilder
the deep comparison of twobyte
arrays.append
(byte lhs, byte rhs) Appends to thebuilder
the comparison of twobyte
s.append
(char[] lhs, char[] rhs) Appends to thebuilder
the deep comparison of twochar
arrays.append
(char lhs, char rhs) Appends to thebuilder
the comparison of twochar
s.append
(double[] lhs, double[] rhs) Appends to thebuilder
the deep comparison of twodouble
arrays.append
(double lhs, double rhs) Appends to thebuilder
the comparison of twodouble
s.append
(float[] lhs, float[] rhs) Appends to thebuilder
the deep comparison of twofloat
arrays.append
(float lhs, float rhs) Appends to thebuilder
the comparison of twofloat
s.append
(int[] lhs, int[] rhs) Appends to thebuilder
the deep comparison of twoint
arrays.append
(int lhs, int rhs) Appends to thebuilder
the comparison of twoint
s.append
(long[] lhs, long[] rhs) Appends to thebuilder
the deep comparison of twolong
arrays.append
(long lhs, long rhs) Appends to thebuilder
the comparison of twolong
s.append
(short[] lhs, short[] rhs) Appends to thebuilder
the deep comparison of twoshort
arrays.append
(short lhs, short rhs) Appends to thebuilder
the comparison of twoshort
s.Appends to thebuilder
the deep comparison of twoObject
arrays.append
(Object[] lhs, Object[] rhs, Comparator comparator) Appends to thebuilder
the deep comparison of twoObject
arrays.Appends to thebuilder
the comparison of twoObject
s.append
(Object lhs, Object rhs, Comparator comparator) Appends to thebuilder
the comparison of twoObject
s.appendSuper
(int superCompareTo) Appends to thebuilder
thecompareTo(Object)
result of the superclass.int
Returns a negative integer, a positive integer, or zero as thebuilder
has judged the "left-hand" side as less than, greater than, or equal to the "right-hand" side.
-
Constructor Details
-
CompareToBuilder
public 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
-
appendSuper
Appends to the
builder
thecompareTo(Object)
result of the superclass.- Parameters:
superCompareTo
- result of callingsuper.compareTo(Object)
- Returns:
- this - used to chain append calls
-
append
Appends to the
builder
the comparison of twoObject
s.- Check if
lhs == rhs
- Check if either
lhs
orrhs
isnull
, anull
object is less than a non-null
object - Check the object contents
lhs
must either be an array or implementComparable
.- Parameters:
lhs
- left-hand objectrhs
- right-hand object- Returns:
- this - used to chain append calls
- Throws:
ClassCastException
- ifrhs
is not assignment-compatible withlhs
- Check if
-
append
Appends to the
builder
the comparison of twoObject
s.- Check if
lhs == rhs
- Check if either
lhs
orrhs
isnull
, anull
object is less than a non-null
object - Check the object contents
If
lhs
is an array, array comparison methods will be used. Otherwisecomparator
will be used to compare the objects. Ifcomparator
isnull
,lhs
must implementComparable
instead.- Parameters:
lhs
- left-hand objectrhs
- right-hand objectcomparator
-Comparator
used to compare the objects,null
means treat lhs asComparable
- Returns:
- this - used to chain append calls
- Throws:
ClassCastException
- ifrhs
is not assignment-compatible withlhs
- Since:
- 2.0
- Check if
-
append
Appends to thebuilder
the comparison of twolong
s.- Parameters:
lhs
- left-hand valuerhs
- right-hand value- Returns:
- this - used to chain append calls
-
append
Appends to thebuilder
the comparison of twoint
s.- Parameters:
lhs
- left-hand valuerhs
- right-hand value- Returns:
- this - used to chain append calls
-
append
Appends to thebuilder
the comparison of twoshort
s.- Parameters:
lhs
- left-hand valuerhs
- right-hand value- Returns:
- this - used to chain append calls
-
append
Appends to thebuilder
the comparison of twochar
s.- Parameters:
lhs
- left-hand valuerhs
- right-hand value- Returns:
- this - used to chain append calls
-
append
Appends to thebuilder
the comparison of twobyte
s.- Parameters:
lhs
- left-hand valuerhs
- right-hand value- Returns:
- this - used to chain append calls
-
append
Appends to the
builder
the comparison of twodouble
s.This handles NaNs, Infinities, and
-0.0
.It is compatible with the hash code generated by
HashCodeBuilder
.- Parameters:
lhs
- left-hand valuerhs
- right-hand value- Returns:
- this - used to chain append calls
-
append
Appends to the
builder
the comparison of twofloat
s.This handles NaNs, Infinities, and
-0.0
.It is compatible with the hash code generated by
HashCodeBuilder
.- Parameters:
lhs
- left-hand valuerhs
- right-hand value- Returns:
- this - used to chain append calls
-
append
Appends to thebuilder
the comparison of twobooleans
s.- Parameters:
lhs
- left-hand valuerhs
- right-hand value- Returns:
- this - used to chain append calls
-
append
Appends to the
builder
the deep comparison of twoObject
arrays.- Check if arrays are the same using
==
- Check if for
null
,null
is 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 arrayrhs
- right-hand array- Returns:
- this - used to chain append calls
- Throws:
ClassCastException
- ifrhs
is not assignment-compatible withlhs
- Check if arrays are the same using
-
append
Appends to the
builder
the deep comparison of twoObject
arrays.- Check if arrays are the same using
==
- Check if for
null
,null
is 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 arrayrhs
- right-hand arraycomparator
-Comparator
to use to compare the array elements,null
means to treatlhs
elements asComparable
.- Returns:
- this - used to chain append calls
- Throws:
ClassCastException
- ifrhs
is not assignment-compatible withlhs
- Since:
- 2.0
- Check if arrays are the same using
-
append
Appends to the
builder
the deep comparison of twolong
arrays.- Check if arrays are the same using
==
- Check if for
null
,null
is 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 arrayrhs
- right-hand array- Returns:
- this - used to chain append calls
- Check if arrays are the same using
-
append
Appends to the
builder
the deep comparison of twoint
arrays.- Check if arrays are the same using
==
- Check if for
null
,null
is 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 arrayrhs
- right-hand array- Returns:
- this - used to chain append calls
- Check if arrays are the same using
-
append
Appends to the
builder
the deep comparison of twoshort
arrays.- Check if arrays are the same using
==
- Check if for
null
,null
is 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 arrayrhs
- right-hand array- Returns:
- this - used to chain append calls
- Check if arrays are the same using
-
append
Appends to the
builder
the deep comparison of twochar
arrays.- Check if arrays are the same using
==
- Check if for
null
,null
is 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 arrayrhs
- right-hand array- Returns:
- this - used to chain append calls
- Check if arrays are the same using
-
append
Appends to the
builder
the deep comparison of twobyte
arrays.- Check if arrays are the same using
==
- Check if for
null
,null
is 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 arrayrhs
- right-hand array- Returns:
- this - used to chain append calls
- Check if arrays are the same using
-
append
Appends to the
builder
the deep comparison of twodouble
arrays.- Check if arrays are the same using
==
- Check if for
null
,null
is 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 arrayrhs
- right-hand array- Returns:
- this - used to chain append calls
- Check if arrays are the same using
-
append
Appends to the
builder
the deep comparison of twofloat
arrays.- Check if arrays are the same using
==
- Check if for
null
,null
is 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 arrayrhs
- right-hand array- Returns:
- this - used to chain append calls
- Check if arrays are the same using
-
append
Appends to the
builder
the deep comparison of twoboolean
arrays.- Check if arrays are the same using
==
- Check if for
null
,null
is 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 arrayrhs
- right-hand array- Returns:
- this - used to chain append calls
- Check if arrays are the same using
-
toComparison
public int toComparison()Returns a negative integer, a positive integer, or zero as thebuilder
has judged the "left-hand" side as less than, greater than, or equal to the "right-hand" side.- Returns:
- final comparison result
-