Top Description Fields Constructors Methods
org.apache.commons.lang3.builder

public Class EqualsBuilder

extends Object
implements Builder<Boolean>
Class Inheritance
All Implemented Interfaces
org.apache.commons.lang3.builder.Builder
Imports
java.lang.reflect.AccessibleObject, .Field, .Modifier, java.util.ArrayList, .Collection, .HashSet, .List, .Set, org.apache.commons.lang3.ArrayUtils, .ClassUtils, org.apache.commons.lang3.tuple.Pair

Assists in implementing Object#equals(Object) methods.

This class provides methods to build a good equals method for any class. It follows rules laid out in Effective Java , by Joshua Bloch. In particular the rule for comparing doubles, floats, and arrays can be tricky. Also, making sure that equals() and hashCode() are consistent can be difficult.

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.

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.

Typical use for the code is as follows:

public boolean equals(Object obj) {
  if (obj == null) { return false; }
  if (obj == this) { return true; }
  if (obj.getClass() != getClass()) {
    return false;
  }
  MyClass rhs = (MyClass) obj;
  return new EqualsBuilder()
                .appendSuper(super.equals(obj))
                .append(field1, rhs.field1)
                .append(field2, rhs.field2)
                .append(field3, rhs.field3)
                .isEquals();
 }

Alternatively, there is a method that uses reflection to determine the fields to test. Because these fields are usually private, the method, reflectionEquals, uses AccessibleObject.setAccessible 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. Non-primitive fields are compared using equals().

A typical invocation for this method would look like:

public boolean equals(Object obj) {
  return EqualsBuilder.reflectionEquals(this, obj);
}

The EqualsExclude annotation can be used to exclude fields from being used by the reflectionEquals methods.

Since
1.0

Field Summary

Modifier and TypeField and Description
private List<Class<?>>
private String[]
private boolean
isEquals

If the fields tested are equals.

private Class<?>
private static final ThreadLocal<Set<Pair<IDKey, IDKey>>>
REGISTRY

A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.

private boolean
private boolean

Constructor Summary

AccessConstructor and Description
public
EqualsBuilder()

Constructor for EqualsBuilder.

Method Summary

Modifier and TypeMethod and Description
public EqualsBuilder

Returns:

this instance.
append
(final boolean
the left-hand side boolean
lhs
,
final boolean
the right-hand side boolean
rhs
)

Test if two booleanss are equal.

public EqualsBuilder

Returns:

this instance.
append
(final boolean[]
the left-hand side boolean[]
lhs
,
final boolean[]
the right-hand side boolean[]
rhs
)

Deep comparison of array of boolean.

public EqualsBuilder

Returns:

this instance.
append
(final byte
the left-hand side byte
lhs
,
final byte
the right-hand side byte
rhs
)

Test if two bytes are equal.

public EqualsBuilder

Returns:

this instance.
append
(final byte[]
the left-hand side byte[]
lhs
,
final byte[]
the right-hand side byte[]
rhs
)

Deep comparison of array of byte.

public EqualsBuilder

Returns:

this instance.
append
(final char
the left-hand side char
lhs
,
final char
the right-hand side char
rhs
)

Test if two chars are equal.

public EqualsBuilder

Returns:

this instance.
append
(final char[]
the left-hand side char[]
lhs
,
final char[]
the right-hand side char[]
rhs
)

Deep comparison of array of char.

public EqualsBuilder

Returns:

this instance.
append
(final double
the left-hand side double
lhs
,
final double
the right-hand side double
rhs
)

Test if two doubles are equal by testing that the pattern of bits returned by doubleToLong are equal.

public EqualsBuilder

Returns:

this instance.
append
(final double[]
the left-hand side double[]
lhs
,
final double[]
the right-hand side double[]
rhs
)

Deep comparison of array of double.

public EqualsBuilder

Returns:

this instance.
append
(final float
the left-hand side float
lhs
,
final float
the right-hand side float
rhs
)

Test if two floats are equal by testing that the pattern of bits returned by doubleToLong are equal.

public EqualsBuilder

Returns:

this instance.
append
(final float[]
the left-hand side float[]
lhs
,
final float[]
the right-hand side float[]
rhs
)

Deep comparison of array of float.

public EqualsBuilder

Returns:

this instance.
append
(final int
the left-hand side int
lhs
,
final int
the right-hand side int
rhs
)

Test if two ints are equal.

public EqualsBuilder

Returns:

this instance.
append
(final int[]
the left-hand side int[]
lhs
,
final int[]
the right-hand side int[]
rhs
)

Deep comparison of array of int.

public EqualsBuilder

Returns:

this instance.
append
(final long
the left-hand side long
lhs
,
final long
the right-hand side long
rhs
)

Test if two longs are equal.

public EqualsBuilder

Returns:

this instance.
append
(final long[]
the left-hand side long[]
lhs
,
final long[]
the right-hand side long[]
rhs
)

Deep comparison of array of long.

public EqualsBuilder

Returns:

this instance.
append
(final Object
the left-hand side object
lhs
,
final Object
the right-hand side object
rhs
)

Test if two Objects are equal using either #reflectionAppend(Object, Object), if object are non primitives (or wrapper of primitives) or if field testRecursive is set to false.

public EqualsBuilder

Returns:

this instance.
append
(final Object[]
the left-hand side Object[]
lhs
,
final Object[]
the right-hand side Object[]
rhs
)

Performs a deep comparison of two Object arrays.

public EqualsBuilder

Returns:

this instance.
append
(final short
the left-hand side short
lhs
,
final short
the right-hand side short
rhs
)

Test if two shorts are equal.

public EqualsBuilder

Returns:

this instance.
append
(final short[]
the left-hand side short[]
lhs
,
final short[]
the right-hand side short[]
rhs
)

Deep comparison of array of short.

private void
appendArray(final Object
the left-hand side object, an array
lhs
,
final Object
the right-hand side object
rhs
)

Test if an Object is equal to an array.

public EqualsBuilder

Returns:

this instance.
appendSuper
(final boolean
the result of calling super.equals()
superEquals
)

Adds the result of super.equals() to this builder.

public Boolean

Returns:

true if all of the fields that have been checked are equal, false otherwise.
build
()

Implements org.apache.commons.lang3.builder.Builder.build.

Returns true if the fields that have been checked are all equal.

pack-priv static Pair<IDKey, IDKey>

Returns:

the pair
getRegisterPair
(final Object
this object
lhs
,
final Object
the other object
rhs
)

Converters value pair into a register pair.

pack-priv static Set<Pair<IDKey, IDKey>>

Returns:

Set the registry of objects being traversed
getRegistry
()

Gets the registry of object pairs being traversed by the reflection methods in the current thread.

public boolean

Returns:

boolean
isEquals
()

Returns true if the fields that have been checked are all equal.

pack-priv static boolean

Returns:

boolean true if the registry contains the given object.
isRegistered
(final Object
this object to lookup in registry
lhs
,
final Object
the other object to lookup on registry
rhs
)

Tests whether the registry contains the given object pair.

public EqualsBuilder

Returns:

this instance.
reflectionAppend
(final Object
the left-hand side object
lhs
,
final Object
the right-hand side object
rhs
)

Tests if two objects by using reflection.

private void
reflectionAppend(final Object
the left-hand side object
lhs
,
final Object
the right-hand side object
rhs
,
final Class<?>
the class to append details of
clazz
)

Appends the fields and values defined by the given object of the given Class.

public static boolean

Returns:

true if the two Objects have tested equals.
reflectionEquals
(final Object
this object
lhs
,
final Object
the other object
rhs
,
final boolean
whether to include transient fields
testTransients
)

This method uses reflection to determine if the two Objects are equal.

public static boolean

Returns:

true if the two Objects have tested equals.
reflectionEquals
(final Object
this object
lhs
,
final Object
the other object
rhs
,
final boolean
whether to include transient fields
testTransients
,
final Class<?>
the superclass to reflect up to (inclusive), may be null
reflectUpToClass
,
final boolean
whether to call reflection equals on non-primitive fields recursively.
testRecursive
,
final String...
array of field names to exclude from testing
excludeFields
)

This method uses reflection to determine if the two Objects are equal.

public static boolean

Returns:

true if the two Objects have tested equals.
reflectionEquals
(final Object
this object
lhs
,
final Object
the other object
rhs
,
final boolean
whether to include transient fields
testTransients
,
final Class<?>
the superclass to reflect up to (inclusive), may be null
reflectUpToClass
,
final String...
array of field names to exclude from testing
excludeFields
)

This method uses reflection to determine if the two Objects are equal.

public static boolean

Returns:

true if the two Objects have tested equals.
reflectionEquals
(final Object
this object
lhs
,
final Object
the other object
rhs
,
final Collection<String>
Collection of String field names to exclude from testing
excludeFields
)

This method uses reflection to determine if the two Objects are equal.

public static boolean

Returns:

true if the two Objects have tested equals.
reflectionEquals
(final Object
this object
lhs
,
final Object
the other object
rhs
,
final String...
array of field names to exclude from testing
excludeFields
)

This method uses reflection to determine if the two Objects are equal.

private static void
register(final Object
this object to register
lhs
,
final Object
the other object to register
rhs
)

Registers the given object pair.

public void
reset()

Reset the EqualsBuilder so you can use the same object again.

public EqualsBuilder

Returns:

this instance.
setBypassReflectionClasses
(final List<Class<?>>
classes to bypass reflection test
bypassReflectionClasses
)

Sets Classes whose instances should be compared by calling their equals although being in recursive mode.

protected void
setEquals(final boolean
The value to set.
isEquals
)

Sets the isEquals value.

public EqualsBuilder

Returns:

this instance.
setExcludeFields
(final String...
the fields to exclude
excludeFields
)

Sets field names to be excluded by reflection tests.

public EqualsBuilder

Returns:

this instance.
setReflectUpToClass
(final Class<?>
the super class to reflect up to
reflectUpToClass
)

Sets the superclass to reflect up to at reflective tests.

public EqualsBuilder

Returns:

this instance.
setTestRecursive
(final boolean
whether to do a recursive test
testRecursive
)

Sets whether to test fields recursively, instead of using their equals method, when reflectively comparing objects.

public EqualsBuilder

Returns:

this instance.
setTestTransients
(final boolean
whether to test transient fields
testTransients
)

Sets whether to include transient fields when reflectively comparing objects.

private static void
unregister(final Object
this object to unregister
lhs
,
final Object
the other object to unregister
rhs
)

Unregisters the given object pair.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bypassReflectionClassesback to summary
private List<Class<?>> bypassReflectionClasses
excludeFieldsback to summary
private String[] excludeFields
isEqualsback to summary
private boolean isEquals

If the fields tested are equals. The default value is true.

reflectUpToClassback to summary
private Class<?> reflectUpToClass
REGISTRYback to summary
private static final ThreadLocal<Set<Pair<IDKey, IDKey>>> REGISTRY

A registry of objects used by reflection methods to detect cyclical object references and avoid infinite loops.

Since
3.0
testRecursiveback to summary
private boolean testRecursive
testTransientsback to summary
private boolean testTransients

Constructor Detail

EqualsBuilderback to summary
public EqualsBuilder()

Constructor for EqualsBuilder.

Starts off assuming that equals is true.

See Also
Object#equals(Object)

Method Detail

appendback to summary
public EqualsBuilder append(final boolean lhs, final boolean rhs)

Test if two booleanss are equal.

Parameters
lhs:boolean

the left-hand side boolean

rhs:boolean

the right-hand side boolean

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final boolean[] lhs, final boolean[] rhs)

Deep comparison of array of boolean. Length and all values are compared.

The method append(boolean, boolean) is used.

Parameters
lhs:boolean[]

the left-hand side boolean[]

rhs:boolean[]

the right-hand side boolean[]

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final byte lhs, final byte rhs)

Test if two bytes are equal.

Parameters
lhs:byte

the left-hand side byte

rhs:byte

the right-hand side byte

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final byte[] lhs, final byte[] rhs)

Deep comparison of array of byte. Length and all values are compared.

The method append(byte, byte) is used.

Parameters
lhs:byte[]

the left-hand side byte[]

rhs:byte[]

the right-hand side byte[]

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final char lhs, final char rhs)

Test if two chars are equal.

Parameters
lhs:char

the left-hand side char

rhs:char

the right-hand side char

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final char[] lhs, final char[] rhs)

Deep comparison of array of char. Length and all values are compared.

The method append(char, char) is used.

Parameters
lhs:char[]

the left-hand side char[]

rhs:char[]

the right-hand side char[]

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final double lhs, final double rhs)

Test if two doubles are equal by testing that the pattern of bits returned by doubleToLong are equal.

This handles NaNs, Infinities, and -0.0.

It is compatible with the hash code generated by HashCodeBuilder.

Parameters
lhs:double

the left-hand side double

rhs:double

the right-hand side double

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final double[] lhs, final double[] rhs)

Deep comparison of array of double. Length and all values are compared.

The method append(double, double) is used.

Parameters
lhs:double[]

the left-hand side double[]

rhs:double[]

the right-hand side double[]

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final float lhs, final float rhs)

Test if two floats are equal by testing that the pattern of bits returned by doubleToLong are equal.

This handles NaNs, Infinities, and -0.0.

It is compatible with the hash code generated by HashCodeBuilder.

Parameters
lhs:float

the left-hand side float

rhs:float

the right-hand side float

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final float[] lhs, final float[] rhs)

Deep comparison of array of float. Length and all values are compared.

The method append(float, float) is used.

Parameters
lhs:float[]

the left-hand side float[]

rhs:float[]

the right-hand side float[]

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final int lhs, final int rhs)

Test if two ints are equal.

Parameters
lhs:int

the left-hand side int

rhs:int

the right-hand side int

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final int[] lhs, final int[] rhs)

Deep comparison of array of int. Length and all values are compared.

The method append(int, int) is used.

Parameters
lhs:int[]

the left-hand side int[]

rhs:int[]

the right-hand side int[]

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final long lhs, final long rhs)

Test if two longs are equal.

Parameters
lhs:long

the left-hand side long

rhs:long

the right-hand side long

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final long[] lhs, final long[] rhs)

Deep comparison of array of long. Length and all values are compared.

The method append(long, long) is used.

Parameters
lhs:long[]

the left-hand side long[]

rhs:long[]

the right-hand side long[]

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final Object lhs, final Object rhs)

Test if two Objects are equal using either #reflectionAppend(Object, Object), if object are non primitives (or wrapper of primitives) or if field testRecursive is set to false. Otherwise, using their equals method.

Parameters
lhs:Object

the left-hand side object

rhs:Object

the right-hand side object

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final Object[] lhs, final Object[] rhs)

Performs a deep comparison of two Object arrays.

This also will be called for the top level of multi-dimensional, ragged, and multi-typed arrays.

Note that this method does not compare the type of the arrays; it only compares the contents.

Parameters
lhs:Object[]

the left-hand side Object[]

rhs:Object[]

the right-hand side Object[]

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final short lhs, final short rhs)

Test if two shorts are equal.

Parameters
lhs:short

the left-hand side short

rhs:short

the right-hand side short

Returns:EqualsBuilder

this instance.

appendback to summary
public EqualsBuilder append(final short[] lhs, final short[] rhs)

Deep comparison of array of short. Length and all values are compared.

The method append(short, short) is used.

Parameters
lhs:short[]

the left-hand side short[]

rhs:short[]

the right-hand side short[]

Returns:EqualsBuilder

this instance.

appendArrayback to summary
private void appendArray(final Object lhs, final Object rhs)

Test if an Object is equal to an array.

Parameters
lhs:Object

the left-hand side object, an array

rhs:Object

the right-hand side object

appendSuperback to summary
public EqualsBuilder appendSuper(final boolean superEquals)

Adds the result of super.equals() to this builder.

Parameters
superEquals:boolean

the result of calling super.equals()

Returns:EqualsBuilder

this instance.

Since
2.0
buildback to summary
public Boolean build()

Implements org.apache.commons.lang3.builder.Builder.build.

Returns true if the fields that have been checked are all equal.

Returns:Boolean

true if all of the fields that have been checked are equal, false otherwise.

Annotations
@Override
Since
3.0
getRegisterPairback to summary
pack-priv static Pair<IDKey, IDKey> getRegisterPair(final Object lhs, final Object rhs)

Converters value pair into a register pair.

Parameters
lhs:Object

this object

rhs:Object

the other object

Returns:Pair<IDKey, IDKey>

the pair

getRegistryback to summary
pack-priv static Set<Pair<IDKey, IDKey>> getRegistry()

Gets the registry of object pairs being traversed by the reflection methods in the current thread.

Returns:Set<Pair<IDKey, IDKey>>

Set the registry of objects being traversed

Since
3.0
isEqualsback to summary
public boolean isEquals()

Returns true if the fields that have been checked are all equal.

Returns:boolean

boolean

isRegisteredback to summary
pack-priv static boolean isRegistered(final Object lhs, final Object rhs)

Tests whether the registry contains the given object pair.

Used by the reflection methods to avoid infinite loops. Objects might be swapped therefore a check is needed if the object pair is registered in given or swapped order.

Parameters
lhs:Object

this object to lookup in registry

rhs:Object

the other object to lookup on registry

Returns:boolean

boolean true if the registry contains the given object.

Since
3.0
reflectionAppendback to summary
public EqualsBuilder reflectionAppend(final Object lhs, final Object rhs)

Tests if two objects by using reflection.

It uses AccessibleObject.setAccessible 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. Non-primitive fields are compared using equals().

If the testTransients field is set to true, transient members will be tested, otherwise they are ignored, as they are likely derived fields, and not part of the value of the Object.

Static fields will not be included. Superclass fields will be appended up to and including the specified superclass in field reflectUpToClass. A null superclass is treated as java.lang.Object.

Field names listed in field excludeFields will be ignored.

If either class of the compared objects is contained in bypassReflectionClasses, both objects are compared by calling the equals method of the left-hand side object with the right-hand side object as an argument.

Parameters
lhs:Object

the left-hand side object

rhs:Object

the right-hand side object

Returns:EqualsBuilder

this instance.

reflectionAppendback to summary
private void reflectionAppend(final Object lhs, final Object rhs, final Class<?> clazz)

Appends the fields and values defined by the given object of the given Class.

Parameters
lhs:Object

the left-hand side object

rhs:Object

the right-hand side object

clazz:Class<?>

the class to append details of

reflectionEqualsback to summary
public static boolean reflectionEquals(final Object lhs, final Object rhs, final boolean testTransients)

This method uses reflection to determine if the two Objects are equal.

It uses AccessibleObject.setAccessible 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. Non-primitive fields are compared using equals().

If the TestTransients parameter is set to true, transient members will be tested, otherwise they are ignored, as they are likely derived fields, and not part of the value of the Object.

Static fields will not be tested. Superclass fields will be included.

Parameters
lhs:Object

this object

rhs:Object

the other object

testTransients:boolean

whether to include transient fields

Returns:boolean

true if the two Objects have tested equals.

See Also
EqualsExclude
reflectionEqualsback to summary
public static boolean reflectionEquals(final Object lhs, final Object rhs, final boolean testTransients, final Class<?> reflectUpToClass, final boolean testRecursive, final String... excludeFields)

This method uses reflection to determine if the two Objects are equal.

It uses AccessibleObject.setAccessible 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. Non-primitive fields are compared using equals().

If the testTransients parameter is set to true, transient members will be tested, otherwise they are ignored, as they are likely derived fields, and not part of the value of the Object.

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.

If the testRecursive parameter is set to true, non primitive (and non primitive wrapper) field types will be compared by EqualsBuilder recursively instead of invoking their equals() method. Leading to a deep reflection equals test.

Parameters
lhs:Object

this object

rhs:Object

the other object

testTransients:boolean

whether to include transient fields

reflectUpToClass:Class<?>

the superclass to reflect up to (inclusive), may be null

testRecursive:boolean

whether to call reflection equals on non-primitive fields recursively.

excludeFields:String[]

array of field names to exclude from testing

Returns:boolean

true if the two Objects have tested equals.

Since
3.6
See Also
EqualsExclude
reflectionEqualsback to summary
public static boolean reflectionEquals(final Object lhs, final Object rhs, final boolean testTransients, final Class<?> reflectUpToClass, final String... excludeFields)

This method uses reflection to determine if the two Objects are equal.

It uses AccessibleObject.setAccessible 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. Non-primitive fields are compared using equals().

If the testTransients parameter is set to true, transient members will be tested, otherwise they are ignored, as they are likely derived fields, and not part of the value of the Object.

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.

Parameters
lhs:Object

this object

rhs:Object

the other object

testTransients:boolean

whether to include transient fields

reflectUpToClass:Class<?>

the superclass to reflect up to (inclusive), may be null

excludeFields:String[]

array of field names to exclude from testing

Returns:boolean

true if the two Objects have tested equals.

Since
2.0
See Also
EqualsExclude
reflectionEqualsback to summary
public static boolean reflectionEquals(final Object lhs, final Object rhs, final Collection<String> excludeFields)

This method uses reflection to determine if the two Objects are equal.

It uses AccessibleObject.setAccessible 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. Non-primitive fields are compared using equals().

Transient members will be not be tested, as they are likely derived fields, and not part of the value of the Object.

Static fields will not be tested. Superclass fields will be included.

Parameters
lhs:Object

this object

rhs:Object

the other object

excludeFields:Collection<String>

Collection of String field names to exclude from testing

Returns:boolean

true if the two Objects have tested equals.

See Also
EqualsExclude
reflectionEqualsback to summary
public static boolean reflectionEquals(final Object lhs, final Object rhs, final String... excludeFields)

This method uses reflection to determine if the two Objects are equal.

It uses AccessibleObject.setAccessible 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. Non-primitive fields are compared using equals().

Transient members will be not be tested, as they are likely derived fields, and not part of the value of the Object.

Static fields will not be tested. Superclass fields will be included.

Parameters
lhs:Object

this object

rhs:Object

the other object

excludeFields:String[]

array of field names to exclude from testing

Returns:boolean

true if the two Objects have tested equals.

See Also
EqualsExclude
registerback to summary
private static void register(final Object lhs, final Object rhs)

Registers the given object pair. Used by the reflection methods to avoid infinite loops.

Parameters
lhs:Object

this object to register

rhs:Object

the other object to register

resetback to summary
public void reset()

Reset the EqualsBuilder so you can use the same object again.

Since
2.5
setBypassReflectionClassesback to summary
public EqualsBuilder setBypassReflectionClasses(final List<Class<?>> bypassReflectionClasses)

Sets Classes whose instances should be compared by calling their equals although being in recursive mode. So the fields of these classes will not be compared recursively by reflection.

Here you should name classes having non-transient fields which are cache fields being set lazily.
Prominent example being String class with its hash code cache field. Due to the importance of the String class, it is included in the default bypasses classes. Usually, if you use your own set of classes here, remember to include String class, too.

Parameters
bypassReflectionClasses:List<Class<?>>

classes to bypass reflection test

Returns:EqualsBuilder

this instance.

Since
3.8
See Also
setTestRecursive(boolean)
setEqualsback to summary
protected void setEquals(final boolean isEquals)

Sets the isEquals value.

Parameters
isEquals:boolean

The value to set.

Since
2.1
setExcludeFieldsback to summary
public EqualsBuilder setExcludeFields(final String... excludeFields)

Sets field names to be excluded by reflection tests.

Parameters
excludeFields:String[]

the fields to exclude

Returns:EqualsBuilder

this instance.

Since
3.6
setReflectUpToClassback to summary
public EqualsBuilder setReflectUpToClass(final Class<?> reflectUpToClass)

Sets the superclass to reflect up to at reflective tests.

Parameters
reflectUpToClass:Class<?>

the super class to reflect up to

Returns:EqualsBuilder

this instance.

Since
3.6
setTestRecursiveback to summary
public EqualsBuilder setTestRecursive(final boolean testRecursive)

Sets whether to test fields recursively, instead of using their equals method, when reflectively comparing objects. String objects, which cache a hash value, are automatically excluded from recursive testing. You may specify other exceptions by calling setBypassReflectionClasses(List).

Parameters
testRecursive:boolean

whether to do a recursive test

Returns:EqualsBuilder

this instance.

Since
3.6
See Also
setBypassReflectionClasses(List)
setTestTransientsback to summary
public EqualsBuilder setTestTransients(final boolean testTransients)

Sets whether to include transient fields when reflectively comparing objects.

Parameters
testTransients:boolean

whether to test transient fields

Returns:EqualsBuilder

this instance.

Since
3.6
unregisterback to summary
private static void unregister(final Object lhs, final Object rhs)

Unregisters the given object pair.

Used by the reflection methods to avoid infinite loops.

Parameters
lhs:Object

this object to unregister

rhs:Object

the other object to unregister

Since
3.0