public class DiffBuilder extends java.lang.Object implements Builder<DiffResult>
Assists in implementing 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(this, obj, ToStringStyle.SHORT_PREFIX_STYLE) .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)
.
Diffable
,
Diff
,
DiffResult
,
ToStringStyle
Constructor and Description |
---|
DiffBuilder(java.lang.Object lhs,
java.lang.Object rhs,
ToStringStyle style)
Constructs a builder for the specified objects with the specified style.
|
DiffBuilder(java.lang.Object lhs,
java.lang.Object rhs,
ToStringStyle style,
boolean testTriviallyEqual)
Constructs a builder for the specified objects with the specified style.
|
Modifier and Type | Method and Description |
---|---|
DiffBuilder |
append(java.lang.String fieldName,
boolean[] lhs,
boolean[] rhs)
Test if two
boolean[] s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
boolean lhs,
boolean rhs)
Test if two
boolean s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
byte[] lhs,
byte[] rhs)
Test if two
byte[] s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
byte lhs,
byte rhs)
Test if two
byte s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
char[] lhs,
char[] rhs)
Test if two
char[] s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
char lhs,
char rhs)
Test if two
char s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
DiffResult diffResult)
Append diffs from another
DiffResult . |
DiffBuilder |
append(java.lang.String fieldName,
double[] lhs,
double[] rhs)
Test if two
double[] s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
double lhs,
double rhs)
Test if two
double s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
float[] lhs,
float[] rhs)
Test if two
float[] s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
float lhs,
float rhs)
Test if two
float s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
int[] lhs,
int[] rhs)
Test if two
int[] s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
int lhs,
int rhs)
Test if two
int s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
long[] lhs,
long[] rhs)
Test if two
long[] s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
long lhs,
long rhs)
Test if two
long s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
java.lang.Object[] lhs,
java.lang.Object[] rhs)
Test if two
Object[] s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
java.lang.Object lhs,
java.lang.Object rhs)
Test if two
Objects s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
short[] lhs,
short[] rhs)
Test if two
short[] s are equal. |
DiffBuilder |
append(java.lang.String fieldName,
short lhs,
short rhs)
Test if two
short s are equal. |
DiffResult |
build()
Builds a
DiffResult based on the differences appended to this
builder. |
public DiffBuilder(java.lang.Object lhs, java.lang.Object rhs, ToStringStyle style, boolean testTriviallyEqual)
Constructs a builder for the specified objects with the specified 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 defaulttestTriviallyEqual
- 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 Diff
if the trivially equal
test is enabled and returns true. The result of this test
is never changed throughout the life of this DiffBuilder
.java.lang.IllegalArgumentException
- if lhs
or rhs
is null
public DiffBuilder(java.lang.Object lhs, java.lang.Object rhs, ToStringStyle style)
Constructs a builder for the specified objects with the specified 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.
This delegates to DiffBuilder(Object, Object, ToStringStyle, boolean)
with the testTriviallyEqual flag enabled.
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 null
public DiffBuilder append(java.lang.String fieldName, boolean lhs, boolean rhs)
Test if two boolean
s are equal.
fieldName
- the field namelhs
- the left hand boolean
rhs
- the right hand boolean
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, boolean[] lhs, boolean[] rhs)
Test if two boolean[]
s are equal.
fieldName
- the field namelhs
- the left hand boolean[]
rhs
- the right hand boolean[]
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, byte lhs, byte rhs)
Test if two byte
s are equal.
fieldName
- the field namelhs
- the left hand byte
rhs
- the right hand byte
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, byte[] lhs, byte[] rhs)
Test if two byte[]
s are equal.
fieldName
- the field namelhs
- the left hand byte[]
rhs
- the right hand byte[]
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, char lhs, char rhs)
Test if two char
s are equal.
fieldName
- the field namelhs
- the left hand char
rhs
- the right hand char
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, char[] lhs, char[] rhs)
Test if two char[]
s are equal.
fieldName
- the field namelhs
- the left hand char[]
rhs
- the right hand char[]
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, double lhs, double rhs)
Test if two double
s are equal.
fieldName
- the field namelhs
- the left hand double
rhs
- the right hand double
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, double[] lhs, double[] rhs)
Test if two double[]
s are equal.
fieldName
- the field namelhs
- the left hand double[]
rhs
- the right hand double[]
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, float lhs, float rhs)
Test if two float
s are equal.
fieldName
- the field namelhs
- the left hand float
rhs
- the right hand float
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, float[] lhs, float[] rhs)
Test if two float[]
s are equal.
fieldName
- the field namelhs
- the left hand float[]
rhs
- the right hand float[]
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, int lhs, int rhs)
Test if two int
s are equal.
fieldName
- the field namelhs
- the left hand int
rhs
- the right hand int
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, int[] lhs, int[] rhs)
Test if two int[]
s are equal.
fieldName
- the field namelhs
- the left hand int[]
rhs
- the right hand int[]
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, long lhs, long rhs)
Test if two long
s are equal.
fieldName
- the field namelhs
- the left hand long
rhs
- the right hand long
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, long[] lhs, long[] rhs)
Test if two long[]
s are equal.
fieldName
- the field namelhs
- the left hand long[]
rhs
- the right hand long[]
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, short lhs, short rhs)
Test if two short
s are equal.
fieldName
- the field namelhs
- the left hand short
rhs
- the right hand short
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, short[] lhs, short[] rhs)
Test if two short[]
s are equal.
fieldName
- the field namelhs
- the left hand short[]
rhs
- the right hand short[]
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, java.lang.Object lhs, java.lang.Object rhs)
Test if two Objects
s are equal.
fieldName
- the field namelhs
- the left hand Object
rhs
- the right hand Object
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, java.lang.Object[] lhs, java.lang.Object[] rhs)
Test if two Object[]
s are equal.
fieldName
- the field namelhs
- the left hand Object[]
rhs
- the right hand Object[]
java.lang.IllegalArgumentException
- if field name is null
public DiffBuilder append(java.lang.String fieldName, DiffResult diffResult)
Append diffs from another DiffResult
.
This method is useful if you want 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(); } }
fieldName
- the field namediffResult
- the DiffResult
to appendjava.lang.IllegalArgumentException
- if field name is null
public DiffResult build()
Builds a DiffResult
based on the differences appended to this
builder.
build
in interface Builder<DiffResult>
DiffResult
containing the differences between the two
objects."Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"