org.unitils.reflectionassert.difference
Class MapDifference

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

public class MapDifference
extends Difference

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

Author:
Tim Ducheyne, Filip Neven

Constructor Summary
MapDifference(String message, Object leftValue, Object rightValue, Map<?,?> leftMap, Map<?,?> rightMap)
          Creates a difference.
 
Method Summary
<T,A> T
accept(DifferenceVisitor<T,A> visitor, A argument)
          Double dispatch method.
 void addLeftMissingKey(Object key)
          Adds a key of the left map that is missing in the right map.
 void addRightMissingKey(Object key)
          Adds a key of the right map that is missing in the left map.
 void addValueDifference(Object key, Difference difference)
          Adds a difference for the element at the given key.
 Map<?,?> getLeftMap()
           
 List<Object> getLeftMissingKeys()
          Gets the keys of the left maps that were missing in the right map.
 Map<?,?> getRightMap()
           
 List<Object> getRightMissingKeys()
          Gets the keys of the left maps that were missing in the right map.
 Map<Object,Difference> getValueDifferences()
          Gets all element differences per key.
 
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

MapDifference

public MapDifference(String message,
                     Object leftValue,
                     Object rightValue,
                     Map<?,?> leftMap,
                     Map<?,?> rightMap)
Creates a difference.

Parameters:
message - a message describing the difference
leftValue - the left instance
rightValue - the right instance
leftMap - The left instance as a map
rightMap - The right instance as a map
Method Detail

addValueDifference

public void addValueDifference(Object key,
                               Difference difference)
Adds a difference for the element at the given key.

Parameters:
key - The key
difference - The difference, not null

getValueDifferences

public Map<Object,Difference> getValueDifferences()
Gets all element differences per key.

Returns:
The differences, not null

addLeftMissingKey

public void addLeftMissingKey(Object key)
Adds a key of the left map that is missing in the right map.

Parameters:
key - The left key

getLeftMissingKeys

public List<Object> getLeftMissingKeys()
Gets the keys of the left maps that were missing in the right map.

Returns:
The keys, not null

addRightMissingKey

public void addRightMissingKey(Object key)
Adds a key of the right map that is missing in the left map.

Parameters:
key - The right key

getRightMissingKeys

public List<Object> getRightMissingKeys()
Gets the keys of the left maps that were missing in the right map.

Returns:
The keys, not null

getLeftMap

public Map<?,?> getLeftMap()
Returns:
The left instance as a map

getRightMap

public Map<?,?> getRightMap()
Returns:
The right instance as a map

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.