Package org.apache.commons.lang3.builder
Class ReflectionDiffBuilder<T>
- java.lang.Object
-
- org.apache.commons.lang3.builder.ReflectionDiffBuilder<T>
-
- Type Parameters:
T
- type of the left and right object to diff.
- All Implemented Interfaces:
Builder<DiffResult<T>>
public class ReflectionDiffBuilder<T> extends java.lang.Object implements Builder<DiffResult<T>>
Assists in implementing
Diffable.diff(Object)
methods.All non-static, non-transient fields (including inherited fields) of the objects to diff are discovered using reflection and compared for differences.
To use this class, write code as follows:
public class Person implements Diffable<Person> { String name; int age; boolean smoker; ... public DiffResult diff(Person obj) { // No need for null check, as NullPointerException correct if obj is null return new ReflectionDiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE) .build(); } }
The
ToStringStyle
passed to the constructor is embedded in the returnedDiffResult
and influences the style of theDiffResult.toString()
method. This style choice can be overridden by callingDiffResult.toString(ToStringStyle)
.- Since:
- 3.6
- See Also:
Diffable
,Diff
,DiffResult
,ToStringStyle
-
-
Constructor Summary
Constructors Constructor Description ReflectionDiffBuilder(T lhs, T rhs, ToStringStyle style)
Constructs a builder for the specified objects with the specified style.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DiffResult<T>
build()
Returns a reference to the object being constructed or result being calculated by the builder.
-
-
-
Constructor Detail
-
ReflectionDiffBuilder
public ReflectionDiffBuilder(T lhs, T rhs, ToStringStyle style)
Constructs a builder for the specified objects with the specified style.
If
lhs == rhs
orlhs.equals(rhs)
then the builder will not evaluate any calls toappend(...)
and will return an emptyDiffResult
whenbuild()
is executed.- Parameters:
lhs
-this
objectrhs
- the object to diff againststyle
- the style will use when outputting the objects,null
uses the default- Throws:
java.lang.IllegalArgumentException
- iflhs
orrhs
isnull
-
-