org.test4j.hamcrest.matcher.property.reflection
类 ReflectionComparator

java.lang.Object
  继承者 org.test4j.hamcrest.matcher.property.reflection.ReflectionComparator

public class ReflectionComparator
extends Object

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.


字段摘要
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.
 
构造方法摘要
ReflectionComparator(List<Comparator> comparators)
          Creates a comparator that will use the given chain.
 
方法摘要
protected  Map<Object,Difference> getCachedDifference(Object left, boolean onlyFirstDifference)
           
 Difference getDifference(Object expectedValue, Object actualValue)
          Checks whether there is a difference between the left and right objects.
 Difference getDifference(Object expectedValue, Object actualValue, boolean onlyFirstDifference)
          Checks whether there are differences between the left and right objects.
 boolean isEqual(Object expectedValue, Object actualValue)
          Checks whether there is no difference between the left and right objects.
protected  void saveResultInCache(Object left, Map<Object,Difference> cachedResult, boolean onlyFirstDifference)
           
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

字段详细信息

comparators

protected List<Comparator> comparators
The comparator chain.


firstDifferenceCachedResults

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.


allDifferencesCachedResults

protected Map<Object,Map<Object,Difference>> allDifferencesCachedResults
构造方法详细信息

ReflectionComparator

public ReflectionComparator(List<Comparator> comparators)
Creates a comparator that will use the given chain.

参数:
comparators - The comparator chain, not null
方法详细信息

isEqual

public boolean isEqual(Object expectedValue,
                       Object actualValue)
Checks whether there is no difference between the left and right objects.

参数:
expectedValue - the left instance
actualValue - the right instance
返回:
true if there is no difference, false otherwise

getDifference

public Difference getDifference(Object expectedValue,
                                Object actualValue)
Checks whether there is a difference between the left and right objects.

参数:
expectedValue - the left instance
actualValue - the right instance
返回:
the difference, null if there is no difference

getDifference

public Difference getDifference(Object expectedValue,
                                Object actualValue,
                                boolean onlyFirstDifference)
Checks whether there are differences between the left and right objects. This will return the root difference of the whole difference tree containing all the differences between the objects.

参数:
expectedValue - the left instance
actualValue - the right instance
onlyFirstDifference - True if the comparison should stop at the first differnece
返回:
the root difference, null if there is no difference

saveResultInCache

protected void saveResultInCache(Object left,
                                 Map<Object,Difference> cachedResult,
                                 boolean onlyFirstDifference)

getCachedDifference

protected Map<Object,Difference> getCachedDifference(Object left,
                                                     boolean onlyFirstDifference)


Copyright © 2013. All rights reserved.