Renamed DiffList to DiffResult as per discussion in LANG-637.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1561225 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Duncan Jones 2014-01-24 23:17:29 +00:00
parent ea47f03c4d
commit 8a82d7b79b
6 changed files with 63 additions and 63 deletions

View File

@ -30,7 +30,7 @@ import org.apache.commons.lang3.tuple.Pair;
*
* <p>
* Typically, {@code Diff}s are retrieved by using a {@link DiffBuilder} to
* produce a {@link DiffList}, containing the differences between two objects.
* produce a {@link DiffResult}, containing the differences between two objects.
* </p>
*
*

View File

@ -39,7 +39,7 @@ import org.apache.commons.lang3.ArrayUtils;
*
* ...
*
* public DiffList diff(Person obj) {
* 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)
@ -52,19 +52,19 @@ import org.apache.commons.lang3.ArrayUtils;
*
* <p>
* The {@code ToStringStyle} passed to the constructor is embedded in the
* returned {@code DiffList} and influences the style of the
* {@code DiffList.toString()} method. This style choice can be overridden by
* calling {@link DiffList#toString(ToStringStyle)}.
* returned {@code DiffResult} and influences the style of the
* {@code DiffResult.toString()} method. This style choice can be overridden by
* calling {@link DiffResult#toString(ToStringStyle)}.
* </p>
*
* @since 3.3
* @version $Id$
* @see Diffable
* @see Diff
* @see DiffList
* @see DiffResult
* @see ToStringStyle
*/
public class DiffBuilder implements Builder<DiffList> {
public class DiffBuilder implements Builder<DiffResult> {
private final List<Diff<?>> diffs;
private final boolean objectsTriviallyEqual;
@ -80,7 +80,7 @@ public class DiffBuilder implements Builder<DiffList> {
* <p>
* If {@code lhs == rhs} or {@code lhs.equals(rhs)} then the builder will
* not evaluate any calls to {@code append(...)} and will return an empty
* {@link DiffList} when {@link #build()} is executed.
* {@link DiffResult} when {@link #build()} is executed.
* </p>
*
* @param lhs
@ -899,16 +899,16 @@ public class DiffBuilder implements Builder<DiffList> {
/**
* <p>
* Builds a {@link DiffList} based on the differences appended to this
* Builds a {@link DiffResult} based on the differences appended to this
* builder.
* </p>
*
* @return a {@code DiffList} containing the differences between the two
* @return a {@code DiffResult} containing the differences between the two
* objects.
*/
@Override
public DiffList build() {
return new DiffList(lhs, rhs, diffs, style);
public DiffResult build() {
return new DiffResult(lhs, rhs, diffs, style);
}
}

View File

@ -22,19 +22,19 @@ import java.util.List;
/**
* <p>
* A {@code DiffList} contains a list of the differences between two
* A {@code DiffResult} contains a collection of the differences between two
* {@link Diffable} objects. Typically these differences are displayed using
* {@link #toString()} method, which returns a string describing the fields that
* differ between the objects.
* </p>
* <p>
* Use a {@link DiffBuilder} to build a {@code DiffList} comparing two objects.
* Use a {@link DiffBuilder} to build a {@code DiffResult} comparing two objects.
* </p>
*
* @since 3.3
* @version $Id$
*/
public class DiffList implements Iterable<Diff<?>> {
public class DiffResult implements Iterable<Diff<?>> {
/**
* <p>
@ -53,7 +53,7 @@ public class DiffList implements Iterable<Diff<?>> {
/**
* <p>
* Creates a {@link DiffList} containing the differences between two
* Creates a {@link DiffResult} containing the differences between two
* objects.
* </p>
*
@ -70,7 +70,7 @@ public class DiffList implements Iterable<Diff<?>> {
* @throws IllegalArgumentException
* if {@code lhs}, {@code rhs} or {@code diffs} is {@code null}
*/
DiffList(final Object lhs, final Object rhs, final List<Diff<?>> diffs,
DiffResult(final Object lhs, final Object rhs, final List<Diff<?>> diffs,
final ToStringStyle style) {
if (lhs == null) {
throw new IllegalArgumentException(
@ -133,7 +133,7 @@ public class DiffList implements Iterable<Diff<?>> {
/**
* <p>
* Builds a {@code String} description of the differences contained within
* this {@code DiffList}. A {@link ToStringBuilder} is used for each object
* this {@code DiffResult}. A {@link ToStringBuilder} is used for each object
* and the style of the output is governed by the {@code ToStringStyle}
* passed to the constructor.
* </p>
@ -169,7 +169,7 @@ public class DiffList implements Iterable<Diff<?>> {
/**
* <p>
* Builds a {@code String} description of the differences contained within
* this {@code DiffList}, using the supplied {@code ToStringStyle}.
* this {@code DiffResult}, using the supplied {@code ToStringStyle}.
* </p>
*
* @param style

View File

@ -18,8 +18,8 @@ package org.apache.commons.lang3.builder;
/**
* <p>{@code Diffable} classes can be compared with other objects
* for differences. The {@link DiffList} object retrieved can be queried
* for a list of differences or printed using the {@link DiffList#toString()}.</p>
* for differences. The {@link DiffResult} object retrieved can be queried
* for a list of differences or printed using the {@link DiffResult#toString()}.</p>
*
* <p>The calculation of the differences is <i>consistent with equals</i> if
* and only if {@code d1.equals(d2)} implies {@code d1.diff(d2) == ""}.
@ -50,5 +50,5 @@ public interface Diffable<T> {
* @return a list of differences
* @throws NullPointerException if the specified object is {@code null}
*/
DiffList diff(T obj);
DiffResult diff(T obj);
}

View File

@ -54,7 +54,7 @@ public class DiffBuilderTest {
private Object[] objectArrayField = {null};
@Override
public DiffList diff(TypeTestClass obj) {
public DiffResult diff(TypeTestClass obj) {
return new DiffBuilder(this, obj, style)
.append("boolean", booleanField, obj.booleanField)
.append("booleanArray", booleanArrayField, obj.booleanArrayField)
@ -94,7 +94,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.booleanField = false;
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertEquals(Boolean.class, diff.getType());
@ -107,7 +107,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.booleanArrayField = new boolean[] {false, false};
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.booleanArrayField),
@ -122,7 +122,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.byteField = 0x01;
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertEquals(Byte.valueOf(class1.byteField), diff.getLeft());
@ -134,7 +134,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.byteArrayField= new byte[] {0x01, 0x02};
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.byteArrayField),
@ -148,7 +148,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.charField = 'z';
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertEquals(Character.valueOf(class1.charField), diff.getLeft());
@ -161,7 +161,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.charArrayField = new char[] {'f', 'o', 'o'};
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.charArrayField),
@ -176,7 +176,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.doubleField = 99.99;
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertEquals(Double.valueOf(class1.doubleField), diff.getLeft());
@ -189,7 +189,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.doubleArrayField = new double[] {3.0, 2.9, 2.8};
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.doubleArrayField),
@ -203,7 +203,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.floatField = 99.99F;
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertEquals(Float.valueOf(class1.floatField), diff.getLeft());
@ -216,7 +216,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.floatArrayField = new float[] {3.0F, 2.9F, 2.8F};
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.floatArrayField),
@ -231,7 +231,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.intField = 42;
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertEquals(Integer.valueOf(class1.intField), diff.getLeft());
@ -244,7 +244,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.intArrayField = new int[] {3, 2, 1};
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.intArrayField),
@ -258,7 +258,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.longField = 42L;
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertEquals(Long.valueOf(class1.longField), diff.getLeft());
@ -271,7 +271,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.longArrayField = new long[] {3L, 2L, 1L};
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.longArrayField),
@ -285,7 +285,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.shortField = 42;
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertEquals(Short.valueOf(class1.shortField), diff.getLeft());
@ -298,7 +298,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.shortArrayField = new short[] {3, 2, 1};
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(ArrayUtils.toObject(class1.shortArrayField),
@ -312,7 +312,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.objectField = "Some string";
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertEquals(class1.objectField, diff.getLeft());
@ -325,7 +325,7 @@ public class DiffBuilderTest {
TypeTestClass class2 = new TypeTestClass();
class1.objectField = "Some string";
class2.objectField = "Some string";
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(0, list.getNumberOfDiffs());
}
@ -335,7 +335,7 @@ public class DiffBuilderTest {
TypeTestClass class1 = new TypeTestClass();
TypeTestClass class2 = new TypeTestClass();
class2.objectArrayField = new Object[] {"string", 1, 2};
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(1, list.getNumberOfDiffs());
Diff<?> diff = list.getDiffs().get(0);
assertArrayEquals(class1.objectArrayField, (Object[]) diff.getLeft());
@ -348,14 +348,14 @@ public class DiffBuilderTest {
TypeTestClass class2 = new TypeTestClass();
class1.objectArrayField = new Object[] {"string", 1, 2};
class2.objectArrayField = new Object[] {"string", 1, 2};
DiffList list = class1.diff(class2);
DiffResult list = class1.diff(class2);
assertEquals(0, list.getNumberOfDiffs());
}
@Test
public void testByteArrayEqualAsObject() throws Exception {
DiffList list = new DiffBuilder("String1", "String2", SHORT_STYLE)
DiffResult list = new DiffBuilder("String1", "String2", SHORT_STYLE)
.append("foo", (Object) new boolean[] {false}, (Object) new boolean[] {false})
.append("foo", (Object) new byte[] {0x01}, (Object) new byte[] {0x01})
.append("foo", (Object) new char[] {'a'}, (Object) new char[] {'a'})
@ -385,7 +385,7 @@ public class DiffBuilderTest {
@Test
public void testSameObjectIgnoresAppends() {
TypeTestClass testClass = new TypeTestClass();
DiffList list = new DiffBuilder(testClass, testClass, SHORT_STYLE)
DiffResult list = new DiffBuilder(testClass, testClass, SHORT_STYLE)
.append("ignored", false, true)
.build();
assertEquals(0, list.getNumberOfDiffs());
@ -395,7 +395,7 @@ public class DiffBuilderTest {
public void testSimilarObjectIgnoresAppends() {
TypeTestClass testClass1 = new TypeTestClass();
TypeTestClass testClass2 = new TypeTestClass();
DiffList list = new DiffBuilder(testClass1, testClass2, SHORT_STYLE)
DiffResult list = new DiffBuilder(testClass1, testClass2, SHORT_STYLE)
.append("ignored", false, true)
.build();
assertEquals(0, list.getNumberOfDiffs());
@ -403,9 +403,9 @@ public class DiffBuilderTest {
@Test
public void testStylePassedToDiffList() {
public void testStylePassedToDiffResult() {
TypeTestClass class1 = new TypeTestClass();
DiffList list = class1.diff(class1);
DiffResult list = class1.diff(class1);
assertEquals(SHORT_STYLE, list.getToStringStyle());
class1.style = ToStringStyle.MULTI_LINE_STYLE;

View File

@ -25,11 +25,11 @@ import java.util.List;
import org.junit.Test;
/**
* Unit tests {@link DiffList}.
* Unit tests {@link DiffResult}.
*
* @version $Id$
*/
public class DiffListTest {
public class DiffResultTest {
private static final SimpleClass SIMPLE_FALSE = new SimpleClass(false);
private static final SimpleClass SIMPLE_TRUE = new SimpleClass(true);
@ -47,7 +47,7 @@ public class DiffListTest {
}
@Override
public DiffList diff(SimpleClass obj) {
public DiffResult diff(SimpleClass obj) {
return new DiffBuilder(this, obj, ToStringStyle.SHORT_PREFIX_STYLE)
.append(getFieldName(), booleanField, obj.booleanField)
.build();
@ -64,7 +64,7 @@ public class DiffListTest {
List<Diff<?>> diffs = lhs.diff(rhs).getDiffs();
DiffList list = new DiffList(lhs, rhs, diffs, SHORT_STYLE);
DiffResult list = new DiffResult(lhs, rhs, diffs, SHORT_STYLE);
assertEquals(diffs, list.getDiffs());
assertEquals(1, list.getNumberOfDiffs());
list.getDiffs().remove(0);
@ -78,7 +78,7 @@ public class DiffListTest {
List<Diff<?>> diffs = lhs.diff(rhs).getDiffs();
Iterator<Diff<?>> expectedIterator = diffs.iterator();
DiffList list = new DiffList(lhs, rhs, diffs, SHORT_STYLE);
DiffResult list = new DiffResult(lhs, rhs, diffs, SHORT_STYLE);
Iterator<Diff<?>> iterator = list.iterator();
while (iterator.hasNext()) {
@ -89,17 +89,17 @@ public class DiffListTest {
@Test
public void testToStringOutput() {
DiffList list = new DiffBuilder(new EmptyClass(), new EmptyClass(),
DiffResult list = new DiffBuilder(new EmptyClass(), new EmptyClass(),
ToStringStyle.SHORT_PREFIX_STYLE).append("test", false, true)
.build();
assertEquals(
"DiffListTest.EmptyClass[test=false] differs from DiffListTest.EmptyClass[test=true]",
"DiffResultTest.EmptyClass[test=false] differs from DiffResultTest.EmptyClass[test=true]",
list.toString());
}
@Test
public void testToStringSpecifyStyleOutput() {
DiffList list = SIMPLE_FALSE.diff(SIMPLE_TRUE);
DiffResult list = SIMPLE_FALSE.diff(SIMPLE_TRUE);
assertTrue(list.getToStringStyle().equals(SHORT_STYLE));
String lhsString = new ToStringBuilder(SIMPLE_FALSE,
@ -118,32 +118,32 @@ public class DiffListTest {
@Test(expected = IllegalArgumentException.class)
public void testNullLhs() {
new DiffList(null, SIMPLE_FALSE, SIMPLE_TRUE.diff(SIMPLE_FALSE)
new DiffResult(null, SIMPLE_FALSE, SIMPLE_TRUE.diff(SIMPLE_FALSE)
.getDiffs(), SHORT_STYLE);
}
@Test(expected = IllegalArgumentException.class)
public void testNullRhs() {
new DiffList(SIMPLE_TRUE, null, SIMPLE_TRUE.diff(SIMPLE_FALSE)
new DiffResult(SIMPLE_TRUE, null, SIMPLE_TRUE.diff(SIMPLE_FALSE)
.getDiffs(), SHORT_STYLE);
}
@Test(expected = IllegalArgumentException.class)
public void testNullList() {
new DiffList(SIMPLE_TRUE, SIMPLE_FALSE, null, SHORT_STYLE);
new DiffResult(SIMPLE_TRUE, SIMPLE_FALSE, null, SHORT_STYLE);
}
@Test
public void testNullStyle() {
DiffList diffList = new DiffList(SIMPLE_TRUE, SIMPLE_FALSE, SIMPLE_TRUE
DiffResult diffResult = new DiffResult(SIMPLE_TRUE, SIMPLE_FALSE, SIMPLE_TRUE
.diff(SIMPLE_FALSE).getDiffs(), null);
assertEquals(ToStringStyle.DEFAULT_STYLE, diffList.getToStringStyle());
assertEquals(ToStringStyle.DEFAULT_STYLE, diffResult.getToStringStyle());
}
@Test
public void testNoDifferencesString() {
DiffList diffList = new DiffBuilder(SIMPLE_TRUE, SIMPLE_TRUE,
DiffResult diffResult = new DiffBuilder(SIMPLE_TRUE, SIMPLE_TRUE,
SHORT_STYLE).build();
assertEquals(DiffList.OBJECTS_SAME_STRING, diffList.toString());
assertEquals(DiffResult.OBJECTS_SAME_STRING, diffResult.toString());
}
}