|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.unitils.reflectionassert.ReflectionComparator
public class ReflectionComparator
A comparator for comparing two values by reflection.
The actual comparison of the values is implemented as a comparator chain. The chain is passed as an argument during the construction. Each of the comparators in the chain is able to compare some types of values. E.g. a CollectionComparator is able to compare collections, simple values such as integers are compared by the SimpleCasesComparator... A number of 'leniency levels' can also be added to the chain: e.g. the LenientOrderCollectionComparator ignores the actual ordering of 2 collections. The preferred way of creating new instances is by using the ReflectionComparatorFactory. This factory will make sure that a correct comparator chain is assembled. A readable report differences can be created using the DifferenceReport.
Field Summary | |
---|---|
protected Map<Object,Map<Object,Difference>> |
allDifferencesCachedResults
|
protected List<Comparator> |
comparators
The comparator chain. |
protected Map<Object,Map<Object,Difference>> |
firstDifferenceCachedResults
A cache of results, so that comparisons are only performed once and infinite loops because of cycles are avoided A different cache is used dependent on whether only the first difference is required or whether we need all differences, since the resulting Difference objects differ. |
Constructor Summary | |
---|---|
ReflectionComparator(List<Comparator> comparators)
Creates a comparator that will use the given chain. |
Method Summary | |
---|---|
protected Map<Object,Difference> |
getCachedDifference(Object left,
boolean onlyFirstDifference)
|
Difference |
getDifference(Object left,
Object right)
Checks whether there is a difference between the left and right objects. |
Difference |
getDifference(Object left,
Object right,
boolean onlyFirstDifference)
Checks whether there are differences between the left and right objects. |
boolean |
isEqual(Object left,
Object right)
Checks whether there is no difference between the left and right objects. |
protected void |
saveResultInCache(Object left,
Map<Object,Difference> cachedResult,
boolean onlyFirstDifference)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected List<Comparator> comparators
protected Map<Object,Map<Object,Difference>> firstDifferenceCachedResults
Difference
objects differ.
protected Map<Object,Map<Object,Difference>> allDifferencesCachedResults
Constructor Detail |
---|
public ReflectionComparator(List<Comparator> comparators)
comparators
- The comparator chain, not nullMethod Detail |
---|
public boolean isEqual(Object left, Object right)
left
- the left instanceright
- the right instance
public Difference getDifference(Object left, Object right)
left
- the left instanceright
- the right instance
public Difference getDifference(Object left, Object right, boolean onlyFirstDifference)
left
- the left instanceright
- the right instanceonlyFirstDifference
- True if the comparison should stop at the first differnece
protected void saveResultInCache(Object left, Map<Object,Difference> cachedResult, boolean onlyFirstDifference)
protected Map<Object,Difference> getCachedDifference(Object left, boolean onlyFirstDifference)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |