T - type of the left and right object to diff.public class ReflectionDiffBuilder<T> extends java.lang.Object implements Builder<DiffResult<T>>
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
returned DiffResult and influences the style of the
DiffResult.toString() method. This style choice can be overridden by
calling DiffResult.toString(ToStringStyle).
See DiffBuilder for a non-reflection based version of this class.
Diffable,
Diff,
DiffResult,
ToStringStyle,
DiffBuilder| Constructor and Description |
|---|
ReflectionDiffBuilder(T lhs,
T rhs,
ToStringStyle style)
Constructs a builder for the specified objects with the specified style.
|
| Modifier and Type | Method and Description |
|---|---|
DiffResult<T> |
build()
Returns a reference to the object being constructed or result being
calculated by the builder.
|
java.lang.String[] |
getExcludeFieldNames()
Gets the field names that should be excluded from the diff.
|
ReflectionDiffBuilder<T> |
setExcludeFieldNames(java.lang.String... excludeFieldNamesParam)
Sets the field names to exclude.
|
public ReflectionDiffBuilder(T lhs, T rhs, ToStringStyle style)
If lhs == rhs or lhs.equals(rhs) then the builder will
not evaluate any calls to append(...) and will return an empty
DiffResult when build() is executed.
lhs - this objectrhs - the object to diff againststyle - the style will use when outputting the objects, null
uses the defaultjava.lang.IllegalArgumentException - if lhs or rhs is nullpublic java.lang.String[] getExcludeFieldNames()
public ReflectionDiffBuilder<T> setExcludeFieldNames(java.lang.String... excludeFieldNamesParam)
excludeFieldNamesParam - The field names to exclude from the diff or null.thispublic DiffResult<T> build()
Builderbuild in interface Builder<DiffResult<T>>Copyright © 2010 - 2023 Adobe. All Rights Reserved