On this page

DiffResult

public class org.apache.commons.lang3.builder.DiffResult<T> implements Iterable<Diff<?>>[source]

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.

Type parameters:

<T> – type of the left and right object.

Since:

3.3

Fields and constants

static final String

OBJECTS_SAME_STRING

The String returned when the objects have no differences: ""

public static final String OBJECTS_SAME_STRING = ""[source]

The String returned when the objects have no differences: ""

Methods

List<Diff<?>>

getDiffs()

Gets an unmodifiable list of Diffs.

T

getLeft()

Gets the object the right object has been compared to.

int

getNumberOfDiffs()

Gets the number of differences between the two objects.

T

getRight()

Gets the object the left object has been compared to.

ToStringStyle

getToStringStyle()

Gets the style used by the toString() method.

Iterator<Diff<?>>

iterator()

Returns an iterator over the Diff objects contained in this list.

String

toString()

Builds a String description of the differences contained within this DiffResult.

String

toString(ToStringStyle style)

Builds a String description of the differences contained within this DiffResult, using the supplied ToStringStyle.

public List<Diff<?>> getDiffs()[source]

Gets an unmodifiable list of Diffs. The list may be empty if there were no differences between the objects.

Returns:

An unmodifiable list of Diffs

public T getLeft()[source]

Gets the object the right object has been compared to.

Returns:

The left object of the diff

Since:

3.10

public int getNumberOfDiffs()[source]

Gets the number of differences between the two objects.

Returns:

The number of differences

public T getRight()[source]

Gets the object the left object has been compared to.

Returns:

The right object of the diff

Since:

3.10

public ToStringStyle getToStringStyle()[source]

Gets the style used by the toString() method.

Returns:

The style

public Iterator<Diff<?>> iterator()[source]

Returns an iterator over the Diff objects contained in this list.

Specified by:

iterator in interface Iterable

Returns:

The iterator

public String toString()[source]

Builds a String description of the differences contained within this DiffResult. A ToStringBuilder is used for each object and the style of the output is governed by the ToStringStyle 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 in Diffable and ToStringStyle.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, use toString(ToStringStyle).

Overrides:

toString in class Object

Returns:

A String description of the differences.

public String toString(ToStringStyle style)[source]

Builds a String description of the differences contained within this DiffResult, using the supplied ToStringStyle.

Parameters:

style – the ToStringStyle to use when outputting the objects

Returns:

A String description of the differences.