org.springmodules.validation.util.condition.range
Class NumberAwareComparableComparator
java.lang.Object
org.springframework.util.comparator.ComparableComparator
org.springmodules.validation.util.condition.range.NumberAwareComparableComparator
- All Implemented Interfaces:
- Comparator
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
| 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(Object o1,
Object o2)
- Compares the two given objects. Expects both of them to be
Comparable instances.
- Specified by:
compare in interface Comparator- Overrides:
compare in class ComparableComparator
- See Also:
ComparableComparator.compare(Object, Object)
compareNumbers
protected int compareNumbers(Number n1,
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 © 2009. All Rights Reserved.