View Javadoc
1   package org.andromda.utils.beans.comparators;
2   
3   import java.io.Serializable;
4   import java.util.Comparator;
5   
6   /**
7    * Used to sort Number values
8    *
9    * @author Chad Brandon
10   */
11  class NumberComparator
12      implements Comparator,
13          Serializable
14  {
15      private static final long serialVersionUID = 34L;
16  
17      /**
18       * Used to sort Number values, both objects are assumed
19       * to be Number instances.
20       * @param objectA
21       * @param objectB
22       * @return compare result
23       */
24      public int compare(
25          final Object objectA,
26          final Object objectB)
27      {
28          final Number aAsNumber = (Number)objectA;
29          final Number bAsNumber = (Number)objectB;
30          int result = 0;
31          if (aAsNumber.doubleValue() > bAsNumber.doubleValue())
32          {
33              result = 1;
34          }
35          else if (aAsNumber.doubleValue() < bAsNumber.doubleValue())
36          {
37              result = -1;
38          }
39          return result;
40      }
41  }