Class DiffResult<T>
- Type Parameters:
T- type of the left and right object.
A DiffResult contains a collection of the differences between two
Diffable objects. Typically these differences are displayed using
toString() method, which returns a string describing the fields that
differ between the objects.
Use a DiffBuilder to build a DiffResult comparing two objects.
- Since:
- 3.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final Tstatic final StringTheStringreturned when the objects have no differences: ""private final Tprivate final ToStringStyle -
Constructor Summary
ConstructorsConstructorDescriptionDiffResult(T lhs, T rhs, List<Diff<?>> diffList, ToStringStyle style) Creates aDiffResultcontaining the differences between two objects. -
Method Summary
Modifier and TypeMethodDescriptiongetDiffs()Returns an unmodifiable list ofDiffs.getLeft()Returns the object the right object has been compared to.intReturns the number of differences between the two objects.getRight()Returns the object the left object has been compared to.Returns the style used by thetoString()method.iterator()Returns an iterator over theDiffobjects contained in this list.toString()Builds aStringdescription of the differences contained within thisDiffResult.toString(ToStringStyle style) Builds aStringdescription of the differences contained within thisDiffResult, using the suppliedToStringStyle.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
OBJECTS_SAME_STRING
The
Stringreturned when the objects have no differences: ""- See Also:
-
DIFFERS_STRING
- See Also:
-
diffList
-
lhs
-
rhs
-
style
-
-
Constructor Details
-
DiffResult
DiffResult(T lhs, T rhs, List<Diff<?>> diffList, ToStringStyle style) Creates a
DiffResultcontaining the differences between two objects.- Parameters:
lhs- the left hand objectrhs- the right hand objectdiffList- the list of differences, may be emptystyle- the style to use for thetoString()method. May benull, in which caseToStringStyle.DEFAULT_STYLEis used- Throws:
NullPointerException- iflhs,rhsordiffsisnull
-
-
Method Details
-
getLeft
Returns the object the right object has been compared to.
- Returns:
- the left object of the diff
- Since:
- 3.10
-
getRight
Returns the object the left object has been compared to.
- Returns:
- the right object of the diff
- Since:
- 3.10
-
getDiffs
Returns an unmodifiable list of
Diffs. The list may be empty if there were no differences between the objects.- Returns:
- an unmodifiable list of
Diffs
-
getNumberOfDiffs
public int getNumberOfDiffs()Returns the number of differences between the two objects.
- Returns:
- the number of differences
-
getToStringStyle
Returns the style used by the
toString()method.- Returns:
- the style
-
toString
Builds a
Stringdescription of the differences contained within thisDiffResult. AToStringBuilderis used for each object and the style of the output is governed by theToStringStylepassed to the constructor.If there are no differences stored in this list, the method will return
OBJECTS_SAME_STRING. Otherwise, using the example given inDiffableandToStringStyle.SHORT_PREFIX_STYLE, an output might be:Person[name=John Doe,age=32] differs from Person[name=Joe Bloggs,age=26]
This indicates that the objects differ in name and age, but not in smoking status.
To use a different
ToStringStylefor an instance of this class, usetoString(ToStringStyle). -
toString
Builds a
Stringdescription of the differences contained within thisDiffResult, using the suppliedToStringStyle.- Parameters:
style- theToStringStyleto use when outputting the objects- Returns:
- a
Stringdescription of the differences.
-
iterator
Returns an iterator over the
Diffobjects contained in this list.
-