org.unitils.reflectionassert.comparator.impl
Class CollectionComparator

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

public class CollectionComparator
extends Object
implements Comparator

Comparator for collections and arrays. All elements are compared in the same order, i.e. element 1 of the left collection with element 1 of the right collection and so on.

Author:
Tim Ducheyne, Filip Neven

Constructor Summary
CollectionComparator()
           
 
Method Summary
 boolean canCompare(Object left, Object right)
          Returns true when both objects are arrays or collections.
 Difference compare(Object left, Object right, boolean onlyFirstDifference, ReflectionComparator reflectionComparator)
          Compared the given collections/arrays.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CollectionComparator

public CollectionComparator()
Method Detail

canCompare

public boolean canCompare(Object left,
                          Object right)
Returns true when both objects are arrays or collections.

Specified by:
canCompare in interface Comparator
Parameters:
left - The left object
right - The right object
Returns:
True in case of arrays/collections

compare

public Difference compare(Object left,
                          Object right,
                          boolean onlyFirstDifference,
                          ReflectionComparator reflectionComparator)
Compared the given collections/arrays.

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


Copyright © 2011. All Rights Reserved.