org.test4j.hamcrest.matcher.property.comparator
类 IgnoreOrderComparator

java.lang.Object
  继承者 org.test4j.hamcrest.matcher.property.comparator.IgnoreOrderComparator
所有已实现的接口:
Comparator

public class IgnoreOrderComparator
extends Object
implements Comparator

A comparator for collections and arrays that ignores the order of both collections. Both collections are found equal if they both contain the same elements (in any order). This implements the LENIENT_ORDER comparison mode.


构造方法摘要
IgnoreOrderComparator()
           
 
方法摘要
 boolean canCompare(Object left, Object right)
          Returns true if both objects are not null and are both Arrays or Collections.
 Difference compare(Object left, Object right, boolean onlyFirstDifference, ReflectionComparator reflectionComparator)
          Compares the given collections/arrays but ignoring the actual order of the elements.
protected  ArrayList<Integer> createIndexList(int size)
           
protected  MatchingScoreCalculator createMatchingScoreCalculator()
          Creates the calculator for determining the matching scores of the differences.
protected  void fillAllDifferences(ArrayList<Object> leftList, ArrayList<Object> rightList, ReflectionComparator reflectionComparator, UnorderedCollectionDifference difference)
          Calculates the difference of all elements in the left list with all elements of the right list.
protected  void fillBestMatchingIndexes(ArrayList<Object> leftList, ArrayList<Object> rightList, UnorderedCollectionDifference difference)
          Calculates the indexes of the best matching differences for the given unordered collection difference.
protected  boolean isEqual(ArrayList<Object> leftList, ArrayList<Object> rightList, int leftIndex, ReflectionComparator reflectionComparator)
          Recursively checks whether there is a sequence so that both collections have matching elements.
protected  void removeMatchingIndexes(ArrayList<Integer> leftIndexes, ArrayList<Integer> rightIndexes, UnorderedCollectionDifference difference)
          Removes all left and right indexes for which there is a match in the given difference object.
protected  void setBestMatchingIndexes(ArrayList<Integer> leftIndexes, ArrayList<Integer> rightIndexes, UnorderedCollectionDifference difference)
          Actual implementation of the best match finding algorithm.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

IgnoreOrderComparator

public IgnoreOrderComparator()
方法详细信息

canCompare

public boolean canCompare(Object left,
                          Object right)
Returns true if both objects are not null and are both Arrays or Collections.

指定者:
接口 Comparator 中的 canCompare
参数:
left - The left object
right - The right object
返回:
True for Arrays and Collections

compare

public Difference compare(Object left,
                          Object right,
                          boolean onlyFirstDifference,
                          ReflectionComparator reflectionComparator)
Compares the given collections/arrays but ignoring the actual order of the elements. This will first try to find a sequence that is an exact match. If no such sequence can be found, the difference of all elements with all other elements are calculated one by one.

指定者:
接口 Comparator 中的 compare
参数:
left - The left array/collection, not null
right - The right array/collection, not null
onlyFirstDifference - True if only the first difference should be returned
reflectionComparator - The root comparator for inner comparisons, not null
返回:
An UnorderedCollectionDifference or null if both collections are equal

isEqual

protected boolean isEqual(ArrayList<Object> leftList,
                          ArrayList<Object> rightList,
                          int leftIndex,
                          ReflectionComparator reflectionComparator)
Recursively checks whether there is a sequence so that both collections have matching elements. This will loop over the elements of the left list and then try to find a match for these elements in the right list. If a match is found, the element is removed from the right collection and the comparison is recursively performed again on the remaining elements.

NOTE: because difference are cached in the reflection comparator, comparing two elements that were already compared should be very fast.

参数:
leftList - The left list, not null
rightList - The right list, not null
leftIndex - The current index in the left collection
reflectionComparator - reflectionComparator The comparator for the element comparisons, not null
返回:
True if a match is found

fillAllDifferences

protected void fillAllDifferences(ArrayList<Object> leftList,
                                  ArrayList<Object> rightList,
                                  ReflectionComparator reflectionComparator,
                                  UnorderedCollectionDifference difference)
Calculates the difference of all elements in the left list with all elements of the right list. The result is added to the given difference.

NOTE: because difference are cached in the reflection comparator, comparing two elements that were already compared should be very fast.

参数:
leftList - The left list, not null
rightList - The right list, not null
reflectionComparator - The comparator for element comparisons, not null
difference - The root difference to which all differences will be added, not null

fillBestMatchingIndexes

protected void fillBestMatchingIndexes(ArrayList<Object> leftList,
                                       ArrayList<Object> rightList,
                                       UnorderedCollectionDifference difference)
Calculates the indexes of the best matching differences for the given unordered collection difference. The resulting indexes are set on the given difference.

Note: The unordered collection difference should contain the differences of all left-elements with all right-elements.

参数:
leftList - The left list, not null
rightList - The right list, not null
difference - The difference to which all indexes will be added, not null

setBestMatchingIndexes

protected void setBestMatchingIndexes(ArrayList<Integer> leftIndexes,
                                      ArrayList<Integer> rightIndexes,
                                      UnorderedCollectionDifference difference)
Actual implementation of the best match finding algorithm. This will loop over the different elements in the collections to the match with the lowest total matching score. These indexes are then set on the given difference. The matching scores are determined by the given matchingScoreCalculator.

参数:
leftIndexes - The current remaining indexes in the left collection, not null
rightIndexes - The current remaining indexes in the right collection, not null
difference - The difference to which all indexes will be added, not null

removeMatchingIndexes

protected void removeMatchingIndexes(ArrayList<Integer> leftIndexes,
                                     ArrayList<Integer> rightIndexes,
                                     UnorderedCollectionDifference difference)
Removes all left and right indexes for which there is a match in the given difference object.

参数:
leftIndexes - The indexes, not null
rightIndexes - The indexes, not null
difference - The collection difference, not null

createIndexList

protected ArrayList<Integer> createIndexList(int size)
参数:
size - The nr of elements
返回:
A list containing 0, 1, 2, ..., not null

createMatchingScoreCalculator

protected MatchingScoreCalculator createMatchingScoreCalculator()
Creates the calculator for determining the matching scores of the differences. These scores are used to determine the best matching elements.

返回:
The instance, not null


Copyright © 2013. All rights reserved.