View Javadoc

1   package com.atlassian.plugin;
2   
3   import java.io.Serializable;
4   import java.util.Comparator;
5   
6   /**
7    * Compares two plugins by their names
8    */
9   class PluginNameComparator implements Comparator<Plugin>, Serializable
10  {
11      static final long serialVersionUID = -2595168544386708474L;
12  
13      /**
14       * Gets names of the two given plugins and returns the result of their comparison
15       *
16       * @param p1 plugin to compare
17       * @param p2 plugin to compare
18       * @return result of plugin name comparison
19       */
20      public int compare(final Plugin p1, final Plugin p2)
21      {
22          final String name1 = p1.getName();
23          final String name2 = p2.getName();
24          if ((name1 == null) || (name2 == null)) {
25              return (name1 == null) ? (name2 == null) ? 0 : -1 : 1;
26          }
27          return name1.compareTo(name2);
28      }
29  }