|
||||||||||
| 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 java.util.Map<java.lang.Object,java.util.Map<java.lang.Object,Difference>> |
allDifferencesCachedResults
|
protected java.util.List<Comparator> |
comparators
The comparator chain. |
protected java.util.Map<java.lang.Object,java.util.Map<java.lang.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(java.util.List<Comparator> comparators)
Creates a comparator that will use the given chain. |
|
| Method Summary | |
|---|---|
protected java.util.Map<java.lang.Object,Difference> |
getCachedDifference(java.lang.Object left,
boolean onlyFirstDifference)
|
Difference |
getDifference(java.lang.Object left,
java.lang.Object right)
Checks whether there is a difference between the left and right objects. |
Difference |
getDifference(java.lang.Object left,
java.lang.Object right,
boolean onlyFirstDifference)
Checks whether there are differences between the left and right objects. |
boolean |
isEqual(java.lang.Object left,
java.lang.Object right)
Checks whether there is no difference between the left and right objects. |
protected void |
saveResultInCache(java.lang.Object left,
java.util.Map<java.lang.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 java.util.List<Comparator> comparators
protected java.util.Map<java.lang.Object,java.util.Map<java.lang.Object,Difference>> firstDifferenceCachedResults
Difference objects differ.
protected java.util.Map<java.lang.Object,java.util.Map<java.lang.Object,Difference>> allDifferencesCachedResults
| Constructor Detail |
|---|
public ReflectionComparator(java.util.List<Comparator> comparators)
comparators - The comparator chain, not null| Method Detail |
|---|
public boolean isEqual(java.lang.Object left,
java.lang.Object right)
left - the left instanceright - the right instance
public Difference getDifference(java.lang.Object left,
java.lang.Object right)
left - the left instanceright - the right instance
public Difference getDifference(java.lang.Object left,
java.lang.Object right,
boolean onlyFirstDifference)
left - the left instanceright - the right instanceonlyFirstDifference - True if the comparison should stop at the first differnece
protected void saveResultInCache(java.lang.Object left,
java.util.Map<java.lang.Object,Difference> cachedResult,
boolean onlyFirstDifference)
protected java.util.Map<java.lang.Object,Difference> getCachedDifference(java.lang.Object left,
boolean onlyFirstDifference)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||