org.unitils.reflectionassert.comparator.impl
Class LenientDatesComparator

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

public class LenientDatesComparator
extends Object
implements Comparator

Comparator that checks whether 2 dates are both null or not null, the actual time-value is not compared. This can be useful when the actual time/date is not known is advance but you still want to check whether a value has been set or not. E.g. a last modification timestamp in the databsse.

Author:
Tim Ducheyne, Filip Neven

Constructor Summary
LenientDatesComparator()
           
 
Method Summary
 boolean canCompare(Object left, Object right)
          Returns true if both objects are null or both objects are Date instances.
 Difference compare(Object left, Object right, boolean onlyFirstDifference, ReflectionComparator reflectionComparator)
          Compares the given dates.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LenientDatesComparator

public LenientDatesComparator()
Method Detail

canCompare

public boolean canCompare(Object left,
                          Object right)
Returns true if both objects are null or both objects are Date instances.

Specified by:
canCompare in interface Comparator
Parameters:
left - The left object
right - The right object
Returns:
True if null or dates

compare

public Difference compare(Object left,
                          Object right,
                          boolean onlyFirstDifference,
                          ReflectionComparator reflectionComparator)
Compares the given dates.

Specified by:
compare in interface Comparator
Parameters:
left - The left date
right - The right date
onlyFirstDifference - True if only the first difference should be returned
reflectionComparator - The root comparator for inner comparisons, not null
Returns:
A difference if one of the dates is null and the other one not, else null


Copyright © 2011. All Rights Reserved.