org.unitils.reflectionassert.comparator.impl
Class LenientNumberComparator
java.lang.Object
org.unitils.reflectionassert.comparator.impl.LenientNumberComparator
- All Implemented Interfaces:
- Comparator
public class LenientNumberComparator
- extends Object
- implements Comparator
A comparator that compares primitive types by value and not by type.
You can for example compare a double with an integer value.
- Author:
- Tim Ducheyne, Filip Neven
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LenientNumberComparator
public LenientNumberComparator()
canCompare
public boolean canCompare(Object left,
Object right)
- Returns true if both objects are not null and instances of Number or Character.
- Specified by:
canCompare
in interface Comparator
- Parameters:
left
- The left objectright
- The right object
- Returns:
- True for Numbers and Charaters
compare
public Difference compare(Object left,
Object right,
boolean onlyFirstDifference,
ReflectionComparator reflectionComparator)
- Compares the two values by converting them to a double and comparing these double values.
- Specified by:
compare
in interface Comparator
- Parameters:
left
- The left Number or Character, not nullright
- The right Number or Character, not nullonlyFirstDifference
- True if only the first difference should be returnedreflectionComparator
- The root comparator for inner comparisons, not null
- Returns:
- A difference if the values are different, null otherwise
Copyright © 2011. All Rights Reserved.