org.testifyproject.apache.commons.lang.builder.CompareToBuilder Maven / Gradle / Ivy
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in org.testifyproject.testifyprojectpliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org.testifyproject/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.testifyproject.apache.org.testifyproject.testifyprojectmons.lang.builder;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.Comparator;
import org.testifyproject.apache.org.testifyproject.testifyprojectmons.lang.ArrayUtils;
import org.testifyproject.apache.org.testifyproject.testifyprojectmons.lang.math.NumberUtils;
/**
* Assists in implementing {@link java.lang.Comparable#org.testifyproject.testifyprojectpareTo(Object)} methods.
*
* It is consistent with equals(Object)
and
* hashcode()
built with {@link EqualsBuilder} and
* {@link HashCodeBuilder}.
*
* Two Objects that org.testifyproject.testifyprojectpare equal using equals(Object)
should normally
* also org.testifyproject.testifyprojectpare equal using org.testifyproject.testifyprojectpareTo(Object)
.
*
* All relevant fields should be included in the calculation of the
* org.testifyproject.testifyprojectparison. Derived fields may be ignored. The same fields, in the same
* order, should be used in both org.testifyproject.testifyprojectpareTo(Object)
and
* equals(Object)
.
*
* To use this class write code as follows:
*
*
* public class MyClass {
* String field1;
* int field2;
* boolean field3;
*
* ...
*
* public int org.testifyproject.testifyprojectpareTo(Object o) {
* MyClass myClass = (MyClass) o;
* return new CompareToBuilder()
* .appendSuper(super.org.testifyproject.testifyprojectpareTo(o)
* .append(this.field1, myClass.field1)
* .append(this.field2, myClass.field2)
* .append(this.field3, myClass.field3)
* .toComparison();
* }
* }
*
*
* Alternatively, there are {@link #reflectionCompare(Object, Object) reflectionCompare} methods that use
* reflection to determine the fields to append. Because fields can be private,
* reflectionCompare
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.
*
* A typical implementation of org.testifyproject.testifyprojectpareTo(Object)
using
* reflectionCompare
looks like:
*
* public int org.testifyproject.testifyprojectpareTo(Object o) {
* return CompareToBuilder.reflectionCompare(this, o);
* }
*
*
* @see java.lang.Comparable
* @see java.lang.Object#equals(Object)
* @see java.lang.Object#hashCode()
* @see EqualsBuilder
* @see HashCodeBuilder
* @author Apache Software Foundation
* @author Steve Downey
* @author Gary Gregory
* @author Pete Gieser
* @since 1.0
* @version $Id: CompareToBuilder.java 1056843 2011-01-09 00:29:01Z niallp $
*/
public class CompareToBuilder {
/**
* Current state of the org.testifyproject.testifyprojectparison as appended fields are checked.
*/
private int org.testifyproject.testifyprojectparison;
/**
* 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
* {@link #toComparison} to get the result.
*/
public CompareToBuilder() {
super();
org.testifyproject.testifyprojectparison = 0;
}
//-----------------------------------------------------------------------
/**
* Compares two Object
s via reflection.
*
* Fields can be private, thus AccessibleObject.setAccessible
* is used to bypass normal access control checks. This will fail under a
* security manager unless the appropriate permissions are set.
*
*
* - Static fields will not be org.testifyproject.testifyprojectpared
* - Transient members will be not be org.testifyproject.testifyprojectpared, as they are likely derived
* fields
* - Superclass fields will be org.testifyproject.testifyprojectpared
*
*
* If both lhs
and rhs
are null
,
* they are considered equal.
*
* @param lhs left-hand object
* @param rhs right-hand object
* @return a negative integer, zero, or a positive integer as lhs
* is less than, equal to, or greater than rhs
* @throws NullPointerException if either (but not both) parameters are
* null
* @throws ClassCastException if rhs
is not assignment-org.testifyproject.testifyprojectpatible
* with lhs
*/
public static int reflectionCompare(Object lhs, Object rhs) {
return reflectionCompare(lhs, rhs, false, null, null);
}
/**
* Compares two Object
s via reflection.
*
* Fields can be private, thus AccessibleObject.setAccessible
* is used to bypass normal access control checks. This will fail under a
* security manager unless the appropriate permissions are set.
*
*
* - Static fields will not be org.testifyproject.testifyprojectpared
* - If
org.testifyproject.testifyprojectpareTransients
is true
,
* org.testifyproject.testifyprojectpares transient members. Otherwise ignores them, as they
* are likely derived fields.
* - Superclass fields will be org.testifyproject.testifyprojectpared
*
*
* If both lhs
and rhs
are null
,
* they are considered equal.
*
* @param lhs left-hand object
* @param rhs right-hand object
* @param org.testifyproject.testifyprojectpareTransients whether to org.testifyproject.testifyprojectpare transient fields
* @return a negative integer, zero, or a positive integer as lhs
* is less than, equal to, or greater than rhs
* @throws NullPointerException if either lhs
or rhs
* (but not both) is null
* @throws ClassCastException if rhs
is not assignment-org.testifyproject.testifyprojectpatible
* with lhs
*/
public static int reflectionCompare(Object lhs, Object rhs, boolean org.testifyproject.testifyprojectpareTransients) {
return reflectionCompare(lhs, rhs, org.testifyproject.testifyprojectpareTransients, null, null);
}
/**
* Compares two Object
s via reflection.
*
* Fields can be private, thus AccessibleObject.setAccessible
* is used to bypass normal access control checks. This will fail under a
* security manager unless the appropriate permissions are set.
*
*
* - Static fields will not be org.testifyproject.testifyprojectpared
* - If
org.testifyproject.testifyprojectpareTransients
is true
,
* org.testifyproject.testifyprojectpares transient members. Otherwise ignores them, as they
* are likely derived fields.
* - Superclass fields will be org.testifyproject.testifyprojectpared
*
*
* If both lhs
and rhs
are null
,
* they are considered equal.
*
* @param lhs left-hand object
* @param rhs right-hand object
* @param excludeFields Collection of String fields to exclude
* @return a negative integer, zero, or a positive integer as lhs
* is less than, equal to, or greater than rhs
* @throws NullPointerException if either lhs
or rhs
* (but not both) is null
* @throws ClassCastException if rhs
is not assignment-org.testifyproject.testifyprojectpatible
* with lhs
* @since 2.2
*/
public static int reflectionCompare(Object lhs, Object rhs, Collection /*String*/ excludeFields) {
return reflectionCompare(lhs, rhs, ReflectionToStringBuilder.toNoNullStringArray(excludeFields));
}
/**
* Compares two Object
s via reflection.
*
* Fields can be private, thus AccessibleObject.setAccessible
* is used to bypass normal access control checks. This will fail under a
* security manager unless the appropriate permissions are set.
*
*
* - Static fields will not be org.testifyproject.testifyprojectpared
* - If
org.testifyproject.testifyprojectpareTransients
is true
,
* org.testifyproject.testifyprojectpares transient members. Otherwise ignores them, as they
* are likely derived fields.
* - Superclass fields will be org.testifyproject.testifyprojectpared
*
*
* If both lhs
and rhs
are null
,
* they are considered equal.
*
* @param lhs left-hand object
* @param rhs right-hand object
* @param excludeFields array of fields to exclude
* @return a negative integer, zero, or a positive integer as lhs
* is less than, equal to, or greater than rhs
* @throws NullPointerException if either lhs
or rhs
* (but not both) is null
* @throws ClassCastException if rhs
is not assignment-org.testifyproject.testifyprojectpatible
* with lhs
* @since 2.2
*/
public static int reflectionCompare(Object lhs, Object rhs, String[] excludeFields) {
return reflectionCompare(lhs, rhs, false, null, excludeFields);
}
/**
* Compares two Object
s via reflection.
*
* Fields can be private, thus AccessibleObject.setAccessible
* is used to bypass normal access control checks. This will fail under a
* security manager unless the appropriate permissions are set.
*
*
* - Static fields will not be org.testifyproject.testifyprojectpared
* - If the
org.testifyproject.testifyprojectpareTransients
is true
,
* org.testifyproject.testifyprojectpares transient members. Otherwise ignores them, as they
* are likely derived fields.
* - Compares superclass fields up to and including
reflectUpToClass
.
* If reflectUpToClass
is null
, org.testifyproject.testifyprojectpares all superclass fields.
*
*
* If both lhs
and rhs
are null
,
* they are considered equal.
*
* @param lhs left-hand object
* @param rhs right-hand object
* @param org.testifyproject.testifyprojectpareTransients whether to org.testifyproject.testifyprojectpare transient fields
* @param reflectUpToClass last superclass for which fields are org.testifyproject.testifyprojectpared
* @return a negative integer, zero, or a positive integer as lhs
* is less than, equal to, or greater than rhs
* @throws NullPointerException if either lhs
or rhs
* (but not both) is null
* @throws ClassCastException if rhs
is not assignment-org.testifyproject.testifyprojectpatible
* with lhs
* @since 2.0
*/
public static int reflectionCompare(Object lhs, Object rhs, boolean org.testifyproject.testifyprojectpareTransients,
Class reflectUpToClass)
{
return reflectionCompare(lhs, rhs, org.testifyproject.testifyprojectpareTransients, reflectUpToClass, null);
}
/**
* Compares two Object
s via reflection.
*
* Fields can be private, thus AccessibleObject.setAccessible
* is used to bypass normal access control checks. This will fail under a
* security manager unless the appropriate permissions are set.
*
*
* - Static fields will not be org.testifyproject.testifyprojectpared
* - If the
org.testifyproject.testifyprojectpareTransients
is true
,
* org.testifyproject.testifyprojectpares transient members. Otherwise ignores them, as they
* are likely derived fields.
* - Compares superclass fields up to and including
reflectUpToClass
.
* If reflectUpToClass
is null
, org.testifyproject.testifyprojectpares all superclass fields.
*
*
* If both lhs
and rhs
are null
,
* they are considered equal.
*
* @param lhs left-hand object
* @param rhs right-hand object
* @param org.testifyproject.testifyprojectpareTransients whether to org.testifyproject.testifyprojectpare transient fields
* @param reflectUpToClass last superclass for which fields are org.testifyproject.testifyprojectpared
* @param excludeFields fields to exclude
* @return a negative integer, zero, or a positive integer as lhs
* is less than, equal to, or greater than rhs
* @throws NullPointerException if either lhs
or rhs
* (but not both) is null
* @throws ClassCastException if rhs
is not assignment-org.testifyproject.testifyprojectpatible
* with lhs
* @since 2.2
*/
public static int reflectionCompare(
Object lhs,
Object rhs,
boolean org.testifyproject.testifyprojectpareTransients,
Class reflectUpToClass,
String[] excludeFields) {
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 org.testifyproject.testifyprojectpareToBuilder = new CompareToBuilder();
reflectionAppend(lhs, rhs, lhsClazz, org.testifyproject.testifyprojectpareToBuilder, org.testifyproject.testifyprojectpareTransients, excludeFields);
while (lhsClazz.getSuperclass() != null && lhsClazz != reflectUpToClass) {
lhsClazz = lhsClazz.getSuperclass();
reflectionAppend(lhs, rhs, lhsClazz, org.testifyproject.testifyprojectpareToBuilder, org.testifyproject.testifyprojectpareTransients, excludeFields);
}
return org.testifyproject.testifyprojectpareToBuilder.toComparison();
}
/**
* Appends to builder
the org.testifyproject.testifyprojectparison of lhs
* to rhs
using the fields defined in clazz
.
*
* @param lhs left-hand object
* @param rhs right-hand object
* @param clazz Class
that defines fields to be org.testifyproject.testifyprojectpared
* @param builder CompareToBuilder
to append to
* @param useTransients whether to org.testifyproject.testifyprojectpare transient fields
* @param excludeFields fields to exclude
*/
private static void reflectionAppend(
Object lhs,
Object rhs,
Class clazz,
CompareToBuilder builder,
boolean useTransients,
String[] excludeFields) {
Field[] fields = clazz.getDeclaredFields();
AccessibleObject.setAccessible(fields, true);
for (int i = 0; i < fields.length && builder.org.testifyproject.testifyprojectparison == 0; i++) {
Field f = fields[i];
if (!ArrayUtils.contains(excludeFields, f.getName())
&& (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");
}
}
}
}
//-----------------------------------------------------------------------
/**
* Appends to the builder
the org.testifyproject.testifyprojectpareTo(Object)
* result of the superclass.
*
* @param superCompareTo result of calling super.org.testifyproject.testifyprojectpareTo(Object)
* @return this - used to chain append calls
* @since 2.0
*/
public CompareToBuilder appendSuper(int superCompareTo) {
if (org.testifyproject.testifyprojectparison != 0) {
return this;
}
org.testifyproject.testifyprojectparison = superCompareTo;
return this;
}
//-----------------------------------------------------------------------
/**
* Appends to the builder
the org.testifyproject.testifyprojectparison of
* two Object
s.
*
*
* - Check if
lhs == rhs
* - Check if either
lhs
or rhs
is null
,
* a null
object is less than a non-null
object
* - Check the object contents
*
*
* lhs
must either be an array or implement {@link Comparable}.
*
* @param lhs left-hand object
* @param rhs right-hand object
* @return this - used to chain append calls
* @throws ClassCastException if rhs
is not assignment-org.testifyproject.testifyprojectpatible
* with lhs
*/
public CompareToBuilder append(Object lhs, Object rhs) {
return append(lhs, rhs, null);
}
/**
* Appends to the builder
the org.testifyproject.testifyprojectparison of
* two Object
s.
*
*
* - Check if
lhs == rhs
* - Check if either
lhs
or rhs
is null
,
* a null
object is less than a non-null
object
* - Check the object contents
*
*
* If lhs
is an array, array org.testifyproject.testifyprojectparison methods will be used.
* Otherwise org.testifyproject.testifyprojectparator
will be used to org.testifyproject.testifyprojectpare the objects.
* If org.testifyproject.testifyprojectparator
is null
, lhs
must
* implement {@link Comparable} instead.
*
* @param lhs left-hand object
* @param rhs right-hand object
* @param org.testifyproject.testifyprojectparator Comparator
used to org.testifyproject.testifyprojectpare the objects,
* null
means treat lhs as Comparable
* @return this - used to chain append calls
* @throws ClassCastException if rhs
is not assignment-org.testifyproject.testifyprojectpatible
* with lhs
* @since 2.0
*/
public CompareToBuilder append(Object lhs, Object rhs, Comparator org.testifyproject.testifyprojectparator) {
if (org.testifyproject.testifyprojectparison != 0) {
return this;
}
if (lhs == rhs) {
return this;
}
if (lhs == null) {
org.testifyproject.testifyprojectparison = -1;
return this;
}
if (rhs == null) {
org.testifyproject.testifyprojectparison = +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, org.testifyproject.testifyprojectparator);
}
} else {
// the simple case, not an array, just test the element
if (org.testifyproject.testifyprojectparator == null) {
org.testifyproject.testifyprojectparison = ((Comparable) lhs).org.testifyproject.testifyprojectpareTo(rhs);
} else {
org.testifyproject.testifyprojectparison = org.testifyproject.testifyprojectparator.org.testifyproject.testifyprojectpare(lhs, rhs);
}
}
return this;
}
//-------------------------------------------------------------------------
/**
* Appends to the builder
the org.testifyproject.testifyprojectparison of
* two long
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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
org.testifyproject.testifyprojectparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
return this;
}
/**
* Appends to the builder
the org.testifyproject.testifyprojectparison of
* two int
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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
org.testifyproject.testifyprojectparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
return this;
}
/**
* Appends to the builder
the org.testifyproject.testifyprojectparison of
* two short
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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
org.testifyproject.testifyprojectparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
return this;
}
/**
* Appends to the builder
the org.testifyproject.testifyprojectparison of
* two char
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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
org.testifyproject.testifyprojectparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
return this;
}
/**
* Appends to the builder
the org.testifyproject.testifyprojectparison of
* two byte
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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
org.testifyproject.testifyprojectparison = ((lhs < rhs) ? -1 : ((lhs > rhs) ? 1 : 0));
return this;
}
/**
* Appends to the builder
the org.testifyproject.testifyprojectparison of
* two double
s.
*
* This handles NaNs, Infinities, and -0.0
.
*
* It is org.testifyproject.testifyprojectpatible with the hash code generated by
* HashCodeBuilder
.
*
* @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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
org.testifyproject.testifyprojectparison = NumberUtils.org.testifyproject.testifyprojectpare(lhs, rhs);
return this;
}
/**
* Appends to the builder
the org.testifyproject.testifyprojectparison of
* two float
s.
*
* This handles NaNs, Infinities, and -0.0
.
*
* It is org.testifyproject.testifyprojectpatible with the hash code generated by
* HashCodeBuilder
.
*
* @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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
org.testifyproject.testifyprojectparison = NumberUtils.org.testifyproject.testifyprojectpare(lhs, rhs);
return this;
}
/**
* Appends to the builder
the org.testifyproject.testifyprojectparison of
* two booleans
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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
if (lhs == rhs) {
return this;
}
if (lhs == false) {
org.testifyproject.testifyprojectparison = -1;
} else {
org.testifyproject.testifyprojectparison = +1;
}
return this;
}
//-----------------------------------------------------------------------
/**
* Appends to the builder
the deep org.testifyproject.testifyprojectparison of
* two Object
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 {@link #append(Object, Object, Comparator)}
*
*
* This method will also will be called for the top level of multi-dimensional,
* ragged, and multi-typed arrays.
*
* @param lhs left-hand array
* @param rhs right-hand array
* @return this - used to chain append calls
* @throws ClassCastException if rhs
is not assignment-org.testifyproject.testifyprojectpatible
* with lhs
*/
public CompareToBuilder append(Object[] lhs, Object[] rhs) {
return append(lhs, rhs, null);
}
/**
* Appends to the builder
the deep org.testifyproject.testifyprojectparison of
* two Object
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 {@link #append(Object, Object, Comparator)}
*
*
* This method will also will be called for the top level of multi-dimensional,
* ragged, and multi-typed arrays.
*
* @param lhs left-hand array
* @param rhs right-hand array
* @param org.testifyproject.testifyprojectparator Comparator
to use to org.testifyproject.testifyprojectpare the array elements,
* null
means to treat lhs
elements as Comparable
.
* @return this - used to chain append calls
* @throws ClassCastException if rhs
is not assignment-org.testifyproject.testifyprojectpatible
* with lhs
* @since 2.0
*/
public CompareToBuilder append(Object[] lhs, Object[] rhs, Comparator org.testifyproject.testifyprojectparator) {
if (org.testifyproject.testifyprojectparison != 0) {
return this;
}
if (lhs == rhs) {
return this;
}
if (lhs == null) {
org.testifyproject.testifyprojectparison = -1;
return this;
}
if (rhs == null) {
org.testifyproject.testifyprojectparison = +1;
return this;
}
if (lhs.length != rhs.length) {
org.testifyproject.testifyprojectparison = (lhs.length < rhs.length) ? -1 : +1;
return this;
}
for (int i = 0; i < lhs.length && org.testifyproject.testifyprojectparison == 0; i++) {
append(lhs[i], rhs[i], org.testifyproject.testifyprojectparator);
}
return this;
}
/**
* Appends to the builder
the deep org.testifyproject.testifyprojectparison of
* two long
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 {@link #append(long, long)}
*
*
* @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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
if (lhs == rhs) {
return this;
}
if (lhs == null) {
org.testifyproject.testifyprojectparison = -1;
return this;
}
if (rhs == null) {
org.testifyproject.testifyprojectparison = +1;
return this;
}
if (lhs.length != rhs.length) {
org.testifyproject.testifyprojectparison = (lhs.length < rhs.length) ? -1 : +1;
return this;
}
for (int i = 0; i < lhs.length && org.testifyproject.testifyprojectparison == 0; i++) {
append(lhs[i], rhs[i]);
}
return this;
}
/**
* Appends to the builder
the deep org.testifyproject.testifyprojectparison of
* two int
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 {@link #append(int, int)}
*
*
* @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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
if (lhs == rhs) {
return this;
}
if (lhs == null) {
org.testifyproject.testifyprojectparison = -1;
return this;
}
if (rhs == null) {
org.testifyproject.testifyprojectparison = +1;
return this;
}
if (lhs.length != rhs.length) {
org.testifyproject.testifyprojectparison = (lhs.length < rhs.length) ? -1 : +1;
return this;
}
for (int i = 0; i < lhs.length && org.testifyproject.testifyprojectparison == 0; i++) {
append(lhs[i], rhs[i]);
}
return this;
}
/**
* Appends to the builder
the deep org.testifyproject.testifyprojectparison of
* two short
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 {@link #append(short, short)}
*
*
* @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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
if (lhs == rhs) {
return this;
}
if (lhs == null) {
org.testifyproject.testifyprojectparison = -1;
return this;
}
if (rhs == null) {
org.testifyproject.testifyprojectparison = +1;
return this;
}
if (lhs.length != rhs.length) {
org.testifyproject.testifyprojectparison = (lhs.length < rhs.length) ? -1 : +1;
return this;
}
for (int i = 0; i < lhs.length && org.testifyproject.testifyprojectparison == 0; i++) {
append(lhs[i], rhs[i]);
}
return this;
}
/**
* Appends to the builder
the deep org.testifyproject.testifyprojectparison of
* two char
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 {@link #append(char, char)}
*
*
* @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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
if (lhs == rhs) {
return this;
}
if (lhs == null) {
org.testifyproject.testifyprojectparison = -1;
return this;
}
if (rhs == null) {
org.testifyproject.testifyprojectparison = +1;
return this;
}
if (lhs.length != rhs.length) {
org.testifyproject.testifyprojectparison = (lhs.length < rhs.length) ? -1 : +1;
return this;
}
for (int i = 0; i < lhs.length && org.testifyproject.testifyprojectparison == 0; i++) {
append(lhs[i], rhs[i]);
}
return this;
}
/**
* Appends to the builder
the deep org.testifyproject.testifyprojectparison of
* two byte
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 {@link #append(byte, byte)}
*
*
* @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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
if (lhs == rhs) {
return this;
}
if (lhs == null) {
org.testifyproject.testifyprojectparison = -1;
return this;
}
if (rhs == null) {
org.testifyproject.testifyprojectparison = +1;
return this;
}
if (lhs.length != rhs.length) {
org.testifyproject.testifyprojectparison = (lhs.length < rhs.length) ? -1 : +1;
return this;
}
for (int i = 0; i < lhs.length && org.testifyproject.testifyprojectparison == 0; i++) {
append(lhs[i], rhs[i]);
}
return this;
}
/**
* Appends to the builder
the deep org.testifyproject.testifyprojectparison of
* two double
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 {@link #append(double, double)}
*
*
* @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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
if (lhs == rhs) {
return this;
}
if (lhs == null) {
org.testifyproject.testifyprojectparison = -1;
return this;
}
if (rhs == null) {
org.testifyproject.testifyprojectparison = +1;
return this;
}
if (lhs.length != rhs.length) {
org.testifyproject.testifyprojectparison = (lhs.length < rhs.length) ? -1 : +1;
return this;
}
for (int i = 0; i < lhs.length && org.testifyproject.testifyprojectparison == 0; i++) {
append(lhs[i], rhs[i]);
}
return this;
}
/**
* Appends to the builder
the deep org.testifyproject.testifyprojectparison of
* two float
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 {@link #append(float, float)}
*
*
* @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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
if (lhs == rhs) {
return this;
}
if (lhs == null) {
org.testifyproject.testifyprojectparison = -1;
return this;
}
if (rhs == null) {
org.testifyproject.testifyprojectparison = +1;
return this;
}
if (lhs.length != rhs.length) {
org.testifyproject.testifyprojectparison = (lhs.length < rhs.length) ? -1 : +1;
return this;
}
for (int i = 0; i < lhs.length && org.testifyproject.testifyprojectparison == 0; i++) {
append(lhs[i], rhs[i]);
}
return this;
}
/**
* Appends to the builder
the deep org.testifyproject.testifyprojectparison of
* two boolean
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 {@link #append(boolean, boolean)}
*
*
* @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 (org.testifyproject.testifyprojectparison != 0) {
return this;
}
if (lhs == rhs) {
return this;
}
if (lhs == null) {
org.testifyproject.testifyprojectparison = -1;
return this;
}
if (rhs == null) {
org.testifyproject.testifyprojectparison = +1;
return this;
}
if (lhs.length != rhs.length) {
org.testifyproject.testifyprojectparison = (lhs.length < rhs.length) ? -1 : +1;
return this;
}
for (int i = 0; i < lhs.length && org.testifyproject.testifyprojectparison == 0; i++) {
append(lhs[i], rhs[i]);
}
return this;
}
//-----------------------------------------------------------------------
/**
* Returns a negative integer, a positive integer, or zero as
* the builder
has judged the "left-hand" side
* as less than, greater than, or equal to the "right-hand"
* side.
*
* @return final org.testifyproject.testifyprojectparison result
*/
public int toComparison() {
return org.testifyproject.testifyprojectparison;
}
}