Class DiffBuilder<T>
- Type Parameters:
- T- type of the left and right object.
- All Implemented Interfaces:
- Builder<DiffResult<T>>
Diffable.diff(Object) methods.
 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 DiffBuilder.<Person>builder()
         .setLeft(this)
         .setRight(obj)
         .setStyle(ToStringStyle.SHORT_PREFIX_STYLE))
         .build()
       .append("name", this.name, obj.name)
       .append("age", this.age, obj.age)
       .append("smoker", this.smoker, obj.smoker)
       .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 ReflectionDiffBuilder for a reflection based version of this class.
 
- Since:
- 3.3
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic final classConstructs a new instance.
- 
Constructor SummaryConstructorsConstructorDescriptionDiffBuilder(T left, T right, ToStringStyle style) Deprecated.DiffBuilder(T left, T right, ToStringStyle style, boolean testObjectsEquals) Deprecated.UseDiffBuilder.Builder.
- 
Method SummaryModifier and TypeMethodDescriptionTests if twoboolean[]s are equal.Tests if twobooleans are equal.Tests if twobyte[]s are equal.Tests if twobytes are equal.Tests if twochar[]s are equal.Tests if twochars are equal.Tests if twodouble[]s are equal.Tests if twodoubles are equal.Tests if twofloat[]s are equal.Test if twofloats are equal.Tests if twoint[]s are equal.Tests if twoints are equal.Tests if twolong[]s are equal.Tests if twolongs are equal.Tests if twoshort[]s are equal.Tests if twoshorts are equal.Tests if twoObject[]s are equal.Tests if twoObjectss are equal.append(String fieldName, DiffResult<?> diffResult) Appends diffs from anotherDiffResult.build()Builds aDiffResultbased on the differences appended to this builder.static <T> DiffBuilder.Builder<T>builder()Constructs a newDiffBuilder.Builder.
- 
Constructor Details- 
DiffBuilderDeprecated.UseDiffBuilder.Builder.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.This delegates to DiffBuilder(Object, Object, ToStringStyle, boolean)with the testTriviallyEqual flag enabled.- Parameters:
- left-- thisobject
- right- the object to diff against
- style- the style to use when outputting the objects,- nulluses the default
- Throws:
- NullPointerException- if- lhsor- rhsis- null
 
- 
DiffBuilderDeprecated.UseDiffBuilder.Builder.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:
- left-- thisobject
- right- the object to diff against
- style- the style to use when outputting the objects,- nulluses the default
- testObjectsEquals- If true, this will test if lhs and rhs are the same or equal. All of the append(fieldName, lhs, rhs) methods will abort without creating a field- Diffif the trivially equal test is enabled and returns true. The result of this test is never changed throughout the life of this- DiffBuilder.
- Throws:
- NullPointerException- if- lhsor- rhsis- null
- Since:
- 3.4
 
 
- 
- 
Method Details- 
builderConstructs a newDiffBuilder.Builder.- Type Parameters:
- T- type of the left and right object.
- Returns:
- a new DiffBuilder.Builder.
- Since:
- 3.15.0
 
- 
appendTests if twobooleans are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- boolean
- rhs- the right-hand side- boolean
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twoboolean[]s are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- boolean[]
- rhs- the right-hand side- boolean[]
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twobytes are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- byte
- rhs- the right-hand side- byte
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twobyte[]s are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- byte[]
- rhs- the right-hand side- byte[]
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twochars are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- char
- rhs- the right-hand side- char
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twochar[]s are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- char[]
- rhs- the right-hand side- char[]
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendAppends diffs from anotherDiffResult.Useful this method to compare properties which are themselves Diffable and would like to know which specific part of it is different. public class Person implements Diffable<Person> { String name; Address address; // implements Diffable<Address> ... public DiffResult diff(Person obj) { return new DiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE) .append("name", this.name, obj.name) .append("address", this.address.diff(obj.address)) .build(); } }- Parameters:
- fieldName- the field name
- diffResult- the- DiffResultto append
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- nullor diffResult is- null
- Since:
- 3.5
 
- 
appendTests if twodoubles are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- double
- rhs- the right-hand side- double
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twodouble[]s are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- double[]
- rhs- the right-hand side- double[]
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTest if twofloats are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- float
- rhs- the right-hand side- float
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twofloat[]s are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- float[]
- rhs- the right-hand side- float[]
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twoints are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- int
- rhs- the right-hand side- int
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twoint[]s are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- int[]
- rhs- the right-hand side- int[]
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twolongs are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- long
- rhs- the right-hand side- long
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twolong[]s are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- long[]
- rhs- the right-hand side- long[]
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twoObjectss are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- Object
- rhs- the right-hand side- Object
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twoObject[]s are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- Object[]
- rhs- the right-hand side- Object[]
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twoshorts are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- short
- rhs- the right-hand side- short
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
appendTests if twoshort[]s are equal.- Parameters:
- fieldName- the field name
- lhs- the left-hand side- short[]
- rhs- the right-hand side- short[]
- Returns:
- thisinstance.
- Throws:
- NullPointerException- if field name is- null
 
- 
buildBuilds aDiffResultbased on the differences appended to this builder.- Specified by:
- buildin interface- Builder<T>
- Returns:
- a DiffResultcontaining the differences between the two objects.
 
 
- 
DiffBuilder.Builder.