View Javadoc

1   package com.atlassian.user.search;
2   
3   import com.atlassian.user.Entity;
4   
5   import java.util.Comparator;
6   import java.text.Collator;
7   
8   /**
9    * Compares two {@link Entity} objects using their {@link Entity#getName()} methods and
10   * a collator (which can be provided to the constructor).
11   *
12   * Instances of this class are not thread-safe if created with the no-args constructor because
13   * the Collator instance used for comparison is not thread-safe.
14   */
15  public class EntityNameAlphaComparator implements Comparator<Entity>
16  {
17      private final Collator collator;
18  
19      public EntityNameAlphaComparator(Collator collator)
20      {
21          this.collator = collator;
22      }
23  
24      public EntityNameAlphaComparator()
25      {
26          collator = Collator.getInstance();
27      }
28  
29      public int compare(Entity o1, Entity o2)
30      {
31          return collator.compare(o1.getName(), o2.getName());
32      }
33  }