View Javadoc
1   package org.andromda.utils.beans.comparators;
2   
3   import java.io.Serializable;
4   import java.text.Collator;
5   import java.util.Comparator;
6   
7   /**
8    * Used to sort String values
9    *
10   * @author Chad Brandon
11   */
12  class StringComparator
13      implements Comparator,
14          Serializable
15  {
16      private static final long serialVersionUID = 34L;
17  
18      private Collator collator = null;
19  
20      /**
21       * Used to sort String values, both objects are assumed
22       * to be String instances.
23       * @param objectA
24       * @param objectB
25       * @return compare result
26       */
27      public int compare(
28          final Object objectA,
29          final Object objectB)
30      {
31          this.initializeCollator();
32          return collator.compare(
33              objectA,
34              objectB);
35      }
36  
37      /**
38       * Initializes the Collator
39       */
40      private void initializeCollator()
41      {
42          if (this.collator == null)
43          {
44              this.collator = Collator.getInstance();
45  
46              //set to ignore case
47              collator.setStrength(Collator.PRIMARY);
48          }
49      }
50  }