Interface Diffable<T>
-
- Type Parameters:
T
- the type of objects that this object may be differentiated against
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface Diffable<T>
Diffable
classes can be compared with other objects for differences. TheDiffResult
object retrieved can be queried for a list of differences or printed using theDiffResult.toString()
.The calculation of the differences is consistent with equals if and only if
d1.equals(d2)
impliesd1.diff(d2) == ""
. It is strongly recommended that implementations are consistent with equals to avoid confusion. Note thatnull
is not an instance of any class andd1.diff(null)
should throw aNullPointerException
.Diffable
classes lend themselves well to unit testing, in which a easily readable description of the differences between an anticipated result and an actual result can be retrieved. For example:Assert.assertEquals(expected.diff(result), expected, result);
- Since:
- 3.3
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description DiffResult<T>
diff(T obj)
Retrieves a list of the differences between this object and the supplied object.
-
-
-
Method Detail
-
diff
DiffResult<T> diff(T obj)
Retrieves a list of the differences between this object and the supplied object.
- Parameters:
obj
- the object to diff against, can benull
- Returns:
- a list of differences
- Throws:
java.lang.NullPointerException
- if the specified object isnull
-
-