ReflectionDiffBuilder¶
- public class org.apache.commons.lang3.builder.ReflectionDiffBuilder<T> extends AbstractReflection implements Builder<DiffResult<T>>[source]¶
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<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
ToStringStylepassed to the constructor is embedded in the returnedDiffResultand influences the style of theDiffResult.toString()method. This style choice can be overridden by callingDiffResult#toString(ToStringStyle).See
DiffBuilderfor a non-reflection based version of this class.- Parameters:
<T> – type of the left and right object to diff.
- See also:
- Since:
3.6
Constructors¶
Deprecated. Constructs a builder for the specified objects with the specified style. |
- @Deprecated public ReflectionDiffBuilder(T left, T right, ToStringStyle style)[source]¶
Deprecated: Use
Builder.Constructs a builder for the specified objects with the specified style.
If
left == rightorleft.equals(right)then the builder will not evaluate any calls toappend(...)and will return an emptyDiffResultwhen#build()is executed.- Parameters:
left –
thisobject.right – The object to diff against.
style – The style will use when outputting the objects,
nulluses the default
- Throws:
java.lang.IllegalArgumentException – Thrown if
leftorrightisnull.
Methods¶
Returns a reference to the object being constructed or result being calculated by the builder. |
|
Constructs a new |
|
Gets the field names that should be excluded from the diff. |
|
Deprecated. Sets the field names to exclude. |
- @Override public DiffResult<T> build()[source]¶
Returns a reference to the object being constructed or result being calculated by the builder.
- Throws:
java.lang.SecurityException – Thrown if an underlying accessible object’s method denies the request.
- See also:
- Returns:
The object constructed or result calculated by the builder.
- public static <T> ReflectionDiffBuilder.Builder<T> builder()[source]¶
Constructs a new
Builder.- Type parameters:
<T> – type of the left and right object.
- Returns:
A new
Builder.- Since:
3.15.0
- public String[] getExcludeFieldNames()[source]¶
Gets the field names that should be excluded from the diff.
- Returns:
The excludeFieldNames.
- Since:
3.13.0
- @Deprecated public ReflectionDiffBuilder<T> setExcludeFieldNames(String... excludeFieldNames)[source]¶
Deprecated: Use
Builder#setExcludeFieldNames(String[]).Sets the field names to exclude.
- Parameters:
excludeFieldNames – The field names to exclude from the diff or
null.- Returns:
thisinstance.- Since:
3.13.0