java.lang.Object
com.conveyal.object_differ.ObjectDiffer
Perform a recursive deep comparison of objects.
This is intended for testing that graph building is reproducible and serialization restores an identical graph.
It should be kept relatively simple.
Each instance should be used for only one comparison and thrown away. It is not threadsafe.
The instance holds configuration and state internally.
TODO enforce single usage and/or provide a reset method so ObjectDiffers can be reused.
The object differ started out as a copy of the one supplied by csolem via the Entur OTP branch at
https://github.com/entur/OpenTripPlanner/tree/protostuff_poc but has been mostly rewritten at this point.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcompareTwoObjects(Object a, Object b) This is the main entry point to compare two objects.voidTell the Differ to execute the whole comparison procedure even when comparing two identical object references.booleanvoidignoreClasses(Class... classes) Classes of objects whose contents will not be examined.voidignoreFields(String... fields) Field names to ignore on all objects.void<T> voidsetKeyExtractor(String fieldName, KeyExtractor<T, ?> keyExtractor) Configure the comparison of two copies of a map originally designed to use identity equality on the keys.voidTell the Differ to completely skip fields marked transient.voidUse equals to compare instances of these classes.
-
Constructor Details
-
ObjectDiffer
public ObjectDiffer()
-
-
Method Details
-
enableComparingIdenticalObjects
public void enableComparingIdenticalObjects()Tell the Differ to execute the whole comparison procedure even when comparing two identical object references. Normally such comparisons would be optimized away since they are by definition identical trees of objects. However this is useful in tests of the comparison system itself - there are known to be no differences. -
skipTransientFields
public void skipTransientFields()Tell the Differ to completely skip fields marked transient. The differ will not see any changes introduced when reconstructing these fields after loading. This is useful though if the transient fields are not reconstructed, or look very different after reconstruction. NOTE: this will completely skip over the values in some external library classes like TIntIntMap. -
ignoreFields
Field names to ignore on all objects. -
ignoreClasses
Classes of objects whose contents will not be examined. We will still check that two classes of this same type exist in the object graph, but not compare their contents. Currently does not include subclasses, an exact match of the concrete type is necessary. -
useEquals
Use equals to compare instances of these classes. Currently does not include subclasses, an exact match of the concrete type is necessary. -
setKeyExtractor
Configure the comparison of two copies of a map originally designed to use identity equality on the keys. Ideally the first parameter would be a Class and would apply to any Map with that Class as a key, but type information about Maps is not known at runtime. SeeKeyExtractor.extractKey(java.lang.Object) -
compareTwoObjects
This is the main entry point to compare two objects. It's also called recursively for many other complex objects in the tree. -
hasDifferences
public boolean hasDifferences() -
printSummary
public void printSummary()
-