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<Person> diff(Person obj) {
// No need for null check, as NullPointerException correct if obj is null
return ReflectionDiffBuilder.<Person>builder()
.setDiffBuilder(DiffBuilder.<Person>builder()
.setLeft(this)
.setRight(obj)
.setStyle(ToStringStyle.SHORT_PREFIX_STYLE)
.build())
.setExcludeFieldNames("userName", "password")
.build() // -> ReflectionDiffBuilder
.build(); // -> DiffResult
}
}
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
| Modifier and Type | Class and Description |
|---|---|
| public static class |
| Modifier and Type | Field and Description |
|---|---|
| private final DiffBuilder | |
| private String[] | excludeFieldNames
Field names to exclude from output. |
| Access | Constructor and Description |
|---|---|
| private | |
| public | ReflectionDiffBuilder(final T
this object.the object to diff against. right, final ToStringStyle the style will use when outputting the objects, style)null uses the default
Deprecated
Use
Builder.
Constructs a builder for the specified objects with the specified style. |
| Modifier and Type | Method and Description |
|---|---|
| private boolean | |
| private void | |
| public DiffResult | build()
Implements org. Returns a reference to the object being constructed or result being calculated by the builder. |
| public static < type of the left and right object. T> ReflectionDiffBuilder. | |
| public String[] | Returns: the excludeFieldNames.Gets the field names that should be excluded from the diff. |
| private T | |
| private T | |
| private Object | |
| public ReflectionDiffBuilder | Returns: this instance.The field names to exclude from the diff or excludeFieldNames)null.
Deprecated
Use
Builder#setExcludeFieldNames(String[]).
Sets the field names to exclude. |
| private static String[] |
| diffBuilder | back to summary |
|---|---|
| private final DiffBuilder<T> diffBuilder | |
| excludeFieldNames | back to summary |
|---|---|
| private String[] excludeFieldNames Field names to exclude from output. Intended for fields like | |
| ReflectionDiffBuilder | back to summary |
|---|---|
| private ReflectionDiffBuilder(final DiffBuilder<T> diffBuilder, final String[] excludeFieldNames) | |
| ReflectionDiffBuilder | back to summary |
|---|---|
| public ReflectionDiffBuilder(final T left, final T right, final ToStringStyle style)
Deprecated Use Constructs a builder for the specified objects with the specified style.
If
| |
| accept | back to summary |
|---|---|
| private boolean accept(final Field field) | |
| appendFields | back to summary |
|---|---|
| private void appendFields(final Class<?> clazz) Appends fields using reflection.
| |
| build | back to summary |
|---|---|
| public DiffResult Implements org. Doc from org. Returns a reference to the object being constructed or result being calculated by the builder.
| |
| builder | back to summary |
|---|---|
| public static <T> ReflectionDiffBuilder. Constructs a new
| |
| getExcludeFieldNames | back to summary |
|---|---|
| public String[] getExcludeFieldNames() Gets the field names that should be excluded from the diff.
| |
| getLeft | back to summary |
|---|---|
| private T getLeft() | |
| getRight | back to summary |
|---|---|
| private T getRight() | |
| readField | back to summary |
|---|---|
| private Object readField(final Field field, final Object target) throws IllegalAccessException Reads a
| |
| setExcludeFieldNames | back to summary |
|---|---|
| public ReflectionDiffBuilder Deprecated Sets the field names to exclude.
| |
| toExcludeFieldNames | back to summary |
|---|---|
| private static String[] toExcludeFieldNames(final String[] excludeFieldNames) | |
| Modifier and Type | Field and Description |
|---|---|
| private DiffBuilder | |
| private String[] |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public ReflectionDiffBuilder | Returns: a new configuredReflectionDiffBuilder.Builds a new configured |
| public ReflectionDiffBuilder. | Returns: this instance.the DiffBuilder. diffBuilder)Sets the DiffBuilder. |
| public ReflectionDiffBuilder. | Returns: this instance.field names to exclude. excludeFieldNames)Sets field names to exclude from output. |
| diffBuilder | back to summary |
|---|---|
| private DiffBuilder<T> diffBuilder | |
| excludeFieldNames | back to summary |
|---|---|
| private String[] excludeFieldNames | |
| Builder | back to summary |
|---|---|
| public Builder() Constructs a new instance. | |
| build | back to summary |
|---|---|
| public ReflectionDiffBuilder Builds a new configured
| |
| setDiffBuilder | back to summary |
|---|---|
| public ReflectionDiffBuilder. Sets the DiffBuilder.
| |
| setExcludeFieldNames | back to summary |
|---|---|
| public ReflectionDiffBuilder. Sets field names to exclude from output. Intended for fields like
| |