org.unitils.reflectionassert.comparator.impl
Class MapComparator

java.lang.Object
  extended by org.unitils.reflectionassert.comparator.impl.MapComparator
All Implemented Interfaces:
Comparator

public class MapComparator
extends Object
implements Comparator

Comparator for maps. This will compare all values with corresponding keys.

Author:
Tim Ducheyne, Filip Neven

Constructor Summary
MapComparator()
           
 
Method Summary
 boolean canCompare(Object left, Object right)
          Returns true when both values are not null and instance of Map
 Difference compare(Object left, Object right, boolean onlyFirstDifference, ReflectionComparator reflectionComparator)
          Compares the given maps by looping over the keys and comparing their values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapComparator

public MapComparator()
Method Detail

canCompare

public boolean canCompare(Object left,
                          Object right)
Returns true when both values are not null and instance of Map

Specified by:
canCompare in interface Comparator
Parameters:
left - The left object
right - The right object
Returns:
True for maps

compare

public Difference compare(Object left,
                          Object right,
                          boolean onlyFirstDifference,
                          ReflectionComparator reflectionComparator)
Compares the given maps by looping over the keys and comparing their values. The key values are compared using a strict reflection comparison.

Specified by:
compare in interface Comparator
Parameters:
left - The left map, not null
right - The right map, not null
onlyFirstDifference - True if only the first difference should be returned
reflectionComparator - The root comparator for inner comparisons, not null
Returns:
A MapDifference or null if both maps are equal


Copyright © 2011. All Rights Reserved.