org.unitils.reflectionassert.difference
Class CollectionDifference

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

public class CollectionDifference
extends Difference

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

Author:
Tim Ducheyne, Filip Neven

Constructor Summary
CollectionDifference(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 index, Difference difference)
          Adds a difference for the element at the given index.
 void addLeftMissingIndex(int index)
          Adds an index of a left element that is missing in the right collection.
 void addRightMissingIndex(int index)
          Adds an index of a right element that is missing in the left collection.
 Map<Integer,Difference> getElementDifferences()
          Gets all element differences per index.
 List<?> getLeftList()
           
 List<Integer> getLeftMissingIndexes()
          Gets the indexes of the left elements that were missing in the right collection.
 List<?> getRightList()
           
 List<Integer> getRightMissingIndexes()
          Gets the indexes of the right elements that were missing in the left collection.
 
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

CollectionDifference

public CollectionDifference(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 index,
                                 Difference difference)
Adds a difference for the element at the given index.

Parameters:
index - The element index
difference - The difference, not null

getElementDifferences

public Map<Integer,Difference> getElementDifferences()
Gets all element differences per index.

Returns:
The differences, not null

addLeftMissingIndex

public void addLeftMissingIndex(int index)
Adds an index of a left element that is missing in the right collection.

Parameters:
index - The left element index

getLeftMissingIndexes

public List<Integer> getLeftMissingIndexes()
Gets the indexes of the left elements that were missing in the right collection.

Returns:
The indexes, not null

addRightMissingIndex

public void addRightMissingIndex(int index)
Adds an index of a right element that is missing in the left collection.

Parameters:
index - The right element index

getRightMissingIndexes

public List<Integer> getRightMissingIndexes()
Gets the indexes of the right elements that were missing in the left collection.

Returns:
The indexes, not null

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.