org.apache.commons.lang.builder
クラス EqualsBuilder

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.

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.

reflectionEquals

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.

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.

パラメータ:

lhs - this object

rhs - the other object

戻り値:

true if the two Objects have tested equals.

reflectionEquals

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.

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.

パラメータ:

lhs - this object

rhs - the other object

testTransients - whether to include transient fields

戻り値:

true if the two Objects have tested equals.

reflectionEquals

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.

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.

パラメータ:

lhs - this object

rhs - the other object

testTransients - whether to include transient fields

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