Class DiffResult<T>
- java.lang.Object
-
- org.apache.commons.lang3.builder.DiffResult<T>
-
- Type Parameters:
T
- type of the left and right object.
public class DiffResult<T> extends Object implements Iterable<Diff<?>>
A
DiffResult
contains a collection of the differences between twoDiffable
objects. Typically these differences are displayed usingtoString()
method, which returns a string describing the fields that differ between the objects.Use a
DiffBuilder
to build aDiffResult
comparing two objects.- Since:
- 3.3
-
-
Field Summary
Fields Modifier and Type Field Description static String
OBJECTS_SAME_STRING
TheString
returned when the objects have no differences: ""
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<Diff<?>>
getDiffs()
Returns an unmodifiable list ofDiff
s.T
getLeft()
Returns the object the right object has been compared to.int
getNumberOfDiffs()
Returns the number of differences between the two objects.T
getRight()
Returns the object the left object has been compared to.ToStringStyle
getToStringStyle()
Returns the style used by thetoString()
method.Iterator<Diff<?>>
iterator()
Returns an iterator over theDiff
objects contained in this list.String
toString()
Builds aString
description of the differences contained within thisDiffResult
.String
toString(ToStringStyle style)
Builds aString
description of the differences contained within thisDiffResult
, using the suppliedToStringStyle
.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
OBJECTS_SAME_STRING
public static final String OBJECTS_SAME_STRING
The
String
returned when the objects have no differences: ""- See Also:
- Constant Field Values
-
-
Method Detail
-
getLeft
public T getLeft()
Returns the object the right object has been compared to.
- Returns:
- the left object of the diff
- Since:
- 3.10
-
getRight
public T getRight()
Returns the object the left object has been compared to.
- Returns:
- the right object of the diff
- Since:
- 3.10
-
getDiffs
public List<Diff<?>> getDiffs()
Returns an unmodifiable list of
Diff
s. The list may be empty if there were no differences between the objects.- Returns:
- an unmodifiable list of
Diff
s
-
getNumberOfDiffs
public int getNumberOfDiffs()
Returns the number of differences between the two objects.
- Returns:
- the number of differences
-
getToStringStyle
public ToStringStyle getToStringStyle()
Returns the style used by the
toString()
method.- Returns:
- the style
-
toString
public String toString()
Builds a
String
description of the differences contained within thisDiffResult
. AToStringBuilder
is used for each object and the style of the output is governed by theToStringStyle
passed to the constructor.If there are no differences stored in this list, the method will return
OBJECTS_SAME_STRING
. Otherwise, using the example given inDiffable
andToStringStyle.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
ToStringStyle
for an instance of this class, usetoString(ToStringStyle)
.
-
toString
public String toString(ToStringStyle style)
Builds a
String
description of the differences contained within thisDiffResult
, using the suppliedToStringStyle
.- Parameters:
style
- theToStringStyle
to use when outputting the objects- Returns:
- a
String
description of the differences.
-
-