|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.unitils.reflectionassert.comparator.impl.LenientOrderCollectionComparator
public class LenientOrderCollectionComparator
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.
Constructor Summary | |
---|---|
LenientOrderCollectionComparator()
|
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public LenientOrderCollectionComparator()
Method Detail |
---|
public boolean canCompare(Object left, Object right)
canCompare
in interface Comparator
left
- The left objectright
- The right object
public Difference compare(Object left, Object right, boolean onlyFirstDifference, ReflectionComparator reflectionComparator)
compare
in interface Comparator
left
- The left array/collection, not nullright
- The right array/collection, not nullonlyFirstDifference
- True if only the first difference should be returnedreflectionComparator
- The root comparator for inner comparisons, not null
protected boolean isEqual(ArrayList<Object> leftList, ArrayList<Object> rightList, int leftIndex, ReflectionComparator reflectionComparator)
leftList
- The left list, not nullrightList
- The right list, not nullleftIndex
- The current index in the left collectionreflectionComparator
- reflectionComparator The comparator for the element comparisons, not null
protected void fillAllDifferences(ArrayList<Object> leftList, ArrayList<Object> rightList, ReflectionComparator reflectionComparator, UnorderedCollectionDifference difference)
leftList
- The left list, not nullrightList
- The right list, not nullreflectionComparator
- The comparator for element comparisons, not nulldifference
- The root difference to which all differences will be added, not nullprotected void fillBestMatchingIndexes(ArrayList<Object> leftList, ArrayList<Object> rightList, UnorderedCollectionDifference difference)
leftList
- The left list, not nullrightList
- The right list, not nulldifference
- The difference to which all indexes will be added, not nullprotected void setBestMatchingIndexes(ArrayList<Integer> leftIndexes, ArrayList<Integer> rightIndexes, UnorderedCollectionDifference difference)
leftIndexes
- The current remaining indexes in the left collection, not nullrightIndexes
- The current remaining indexes in the right collection, not nulldifference
- The difference to which all indexes will be added, not nullprotected void removeMatchingIndexes(ArrayList<Integer> leftIndexes, ArrayList<Integer> rightIndexes, UnorderedCollectionDifference difference)
leftIndexes
- The indexes, not nullrightIndexes
- The indexes, not nulldifference
- The collection difference, not nullprotected ArrayList<Integer> createIndexList(int size)
size
- The nr of elements
protected MatchingScoreCalculator createMatchingScoreCalculator()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |