01: package org.andromda.utils.beans.comparators;
02:
03: import java.io.Serializable;
04:
05: import java.util.Comparator;
06:
07: /**
08: * Used to sort Number values
09: *
10: * @author Chad Brandon
11: */
12: class NumberComparator implements Comparator, Serializable {
13: /**
14: * Used to sort Number values, both objects are assumed
15: * to be Number instances.
16: */
17: public int compare(final Object objectA, final Object objectB) {
18: final Number aAsNumber = (Number) objectA;
19: final Number bAsNumber = (Number) objectB;
20: int result = 0;
21: if (aAsNumber.doubleValue() > bAsNumber.doubleValue()) {
22: result = 1;
23: } else if (aAsNumber.doubleValue() < bAsNumber.doubleValue()) {
24: result = -1;
25: }
26: return result;
27: }
28: }
|