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>>
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
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.
- Since:
- 3.6
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionReflectionDiffBuilder(T lhs, T rhs, ToStringStyle style) Constructs a builder for the specified objects with the specified style. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Returns a reference to the object being constructed or result being calculated by the builder.String[]Gets the field names that should be excluded from the diff.setExcludeFieldNames(String... excludeFieldNamesParam) Sets the field names to exclude.
-
Constructor Details
-
ReflectionDiffBuilder
Constructs a builder for the specified objects with the specified style.If
lhs == rhsorlhs.equals(rhs)then the builder will not evaluate any calls toappend(...)and will return an emptyDiffResultwhenbuild()is executed.- Parameters:
lhs-thisobjectrhs- the object to diff againststyle- the style will use when outputting the objects,nulluses the default- Throws:
IllegalArgumentException- iflhsorrhsisnull
-
-
Method Details
-
build
Description copied from interface:BuilderReturns a reference to the object being constructed or result being calculated by the builder. -
getExcludeFieldNames
Gets the field names that should be excluded from the diff.- Returns:
- Returns the excludeFieldNames.
- Since:
- 3.13.0
-
setExcludeFieldNames
Sets the field names to exclude.- Parameters:
excludeFieldNamesParam- The field names to exclude from the diff ornull.- Returns:
this- Since:
- 3.13.0
-