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