org.unitils.reflectionassert.difference
Class UnorderedCollectionDifference

java.lang.Object
  extended by org.unitils.reflectionassert.difference.Difference
      extended by org.unitils.reflectionassert.difference.UnorderedCollectionDifference

public class UnorderedCollectionDifference
extends Difference

A class for holding the difference between all elements of two collections or arrays.

Author:
Tim Ducheyne, Filip Neven

Constructor Summary
UnorderedCollectionDifference(String message, Object leftValue, Object rightValue, List<?> leftList, List<?> rightList)
          Creates a difference.
 
Method Summary
<T,A> T
accept(DifferenceVisitor<T,A> visitor, A argument)
          Double dispatch method.
 void addElementDifference(int leftIndex, int rightIndex, Difference difference)
          Adds a difference or a match for the elements at the given left and right index.
 Map<Integer,Integer> getBestMatchingIndexes()
          Gets the indexes of the best matching element differences.
 int getBestMatchingScore()
          Gets the matching score of the best matching indexes.
 Difference getElementDifference(int leftIndex, int rightIndex)
          Gets the difference between the elements with the given indexes.
 Map<Integer,Map<Integer,Difference>> getElementDifferences()
          Gets all element differences per left index and right index.
 List<?> getLeftList()
           
 List<?> getRightList()
           
 void setBestMatchingIndexes(int leftIndex, int rightIndex)
          Sets the given left and right index as best matching elements.
 void setBestMatchingScore(int bestMatchingScore)
          Gets the matching score of the best matching indexes.
 
Methods inherited from class org.unitils.reflectionassert.difference.Difference
getLeftValue, getMessage, getRightValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnorderedCollectionDifference

public UnorderedCollectionDifference(String message,
                                     Object leftValue,
                                     Object rightValue,
                                     List<?> leftList,
                                     List<?> rightList)
Creates a difference.

Parameters:
message - a message describing the difference
leftValue - the left instance
rightValue - the right instance
leftList - The left instance as a list
rightList - The right instance as a list
Method Detail

addElementDifference

public void addElementDifference(int leftIndex,
                                 int rightIndex,
                                 Difference difference)
Adds a difference or a match for the elements at the given left and right index.

Parameters:
leftIndex - The index of the left element
rightIndex - The index of the right element
difference - The difference, null for a match

getElementDifference

public Difference getElementDifference(int leftIndex,
                                       int rightIndex)
Gets the difference between the elements with the given indexes.

Parameters:
leftIndex - The left element index
rightIndex - The right element index
Returns:
The difference, null if not found or if there is no difference

getElementDifferences

public Map<Integer,Map<Integer,Difference>> getElementDifferences()
Gets all element differences per left index and right index. A null difference means a match.

Returns:
The differences, not null

setBestMatchingIndexes

public void setBestMatchingIndexes(int leftIndex,
                                   int rightIndex)
Sets the given left and right index as best matching elements.

Parameters:
leftIndex - The left index
rightIndex - The right index

getBestMatchingIndexes

public Map<Integer,Integer> getBestMatchingIndexes()
Gets the indexes of the best matching element differences.

Returns:
The indexes, not null

getBestMatchingScore

public int getBestMatchingScore()
Gets the matching score of the best matching indexes.

Returns:
The score

setBestMatchingScore

public void setBestMatchingScore(int bestMatchingScore)
Gets the matching score of the best matching indexes.

Parameters:
bestMatchingScore - The score

getLeftList

public List<?> getLeftList()
Returns:
The left instance as a list

getRightList

public List<?> getRightList()
Returns:
The right instance as a list

accept

public <T,A> T accept(DifferenceVisitor<T,A> visitor,
                      A argument)
Double dispatch method. Dispatches back to the given visitor.

All subclasses should copy this method in their own class body.

Overrides:
accept in class Difference
Parameters:
visitor - The visitor, not null
argument - An optional argument for the visitor, null if not applicable
Returns:
The result


Copyright © 2011. All Rights Reserved.