org.springmodules.validation.util.condition.range
Class NumberAwareComparableComparator
java.lang.Object
ComparableComparator
org.springmodules.validation.util.condition.range.NumberAwareComparableComparator
public class NumberAwareComparableComparator
- extends ComparableComparator
A comparator that compares Comparable instances but treats comparison of Number instances
in a special manner. In order to support comparison of numbers regardless of their type, this comparator transform
the numbers to BigDecimal and then does the comparison.
- Author:
- Uri Boness
|
Method Summary |
int |
compare(java.lang.Object o1,
java.lang.Object o2)
Compares the two given objects. |
protected int |
compareNumbers(java.lang.Number n1,
java.lang.Number n2)
Compares the two given numbers. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
NumberAwareComparableComparator
public NumberAwareComparableComparator()
compare
public int compare(java.lang.Object o1,
java.lang.Object o2)
- Compares the two given objects. Expects both of them to be
Comparable instances.
- See Also:
ComparableComparator#compare(Object, Object)
compareNumbers
protected int compareNumbers(java.lang.Number n1,
java.lang.Number n2)
- Compares the two given numbers. These numbers are compared regardless of their type.
- Parameters:
n1 - The first number.n2 - The second number.
- Returns:
- possitive number if
n1 > n2, negative number if n1 < n2, or 0 (Zero) if
n1 == n2.
Copyright © 2005. All Rights Reserved.