org.unitils.reflectionassert.comparator
Interface Comparator

All Known Implementing Classes:
CollectionComparator, HibernateProxyComparator, IgnoreDefaultsComparator, LenientDatesComparator, LenientNumberComparator, LenientOrderCollectionComparator, MapComparator, ObjectComparator, SimpleCasesComparator

public interface Comparator

Interface for comparing 2 given objects.

One should always first call canCompare before calling compare to perform the actual comparison. If canCompare returns false, the comparator implementation is not suited to compare the given objects and compare should not be called.

Author:
Tim Ducheyne, Filip Neven

Method Summary
 boolean canCompare(Object left, Object right)
          Checks whether this comparator can compare the given objects.
 Difference compare(Object left, Object right, boolean onlyFirstDifference, ReflectionComparator reflectionComparator)
          Compares the given objects and returns the difference (if any).
 

Method Detail

canCompare

boolean canCompare(Object left,
                   Object right)
Checks whether this comparator can compare the given objects.

This method should always be called before calling the compare method. If false is returned compare should not be invoked.

Parameters:
left - The left object
right - The right object
Returns:
True if compare can be called, false otherwise

compare

Difference compare(Object left,
                   Object right,
                   boolean onlyFirstDifference,
                   ReflectionComparator reflectionComparator)
Compares the given objects and returns the difference (if any).

The reflection comparator is passed as an argument and can be used to perform inner comparisons. E.g. during the comparison of an object the given comparator can be used to compare the instance fields of the object.

Parameters:
left - The left object
right - The right object
onlyFirstDifference - True if only the first difference should be returned
reflectionComparator - The root comparator for inner comparisons, not null
Returns:
The difference, null if a match is found


Copyright © 2011. All Rights Reserved.