View Javadoc

1   package com.atlassian.marketplace.client.api;
2   
3   import static com.google.common.base.Preconditions.checkNotNull;
4   import static org.apache.commons.lang.StringUtils.trimToNull;
5   
6   /**
7    * A string that uniquely identifies one of the applications known to the Atlassian
8    * Marketplace.
9    */
10  public final class ApplicationKey
11  {
12      public static final ApplicationKey BAMBOO = new ApplicationKey("bamboo");
13      public static final ApplicationKey BITBUCKET = new ApplicationKey("bitbucket");
14      public static final ApplicationKey CONFLUENCE = new ApplicationKey("confluence");
15      public static final ApplicationKey FECRU = new ApplicationKey("fecru");
16      public static final ApplicationKey HIPCHAT = new ApplicationKey("hipchat");
17      public static final ApplicationKey JIRA = new ApplicationKey("jira");
18  
19      private static final ApplicationKey[] PREDEFINED =
20          { BAMBOO, BITBUCKET, CONFLUENCE, FECRU, HIPCHAT, JIRA };
21      
22      private final String key;
23  
24      private ApplicationKey(String key)
25      {
26          this.key = key;
27      }
28      
29      /**
30       * Returns an ApplicationKey instance corresponding to the given string value.  This is
31       * case-insensitive, e.g. <tt>valueOf("Bamboo")</tt> will return {@link #BAMBOO}. 
32       * @param key  an application key string
33       * @return  an {@link ApplicationKey}
34       * @throws NullPointerException  if key is null, empty, or whitespace
35       */
36      public static ApplicationKey valueOf(String key)
37      {
38          String s = checkNotNull(trimToNull(key)).toLowerCase();
39          for (ApplicationKey a: PREDEFINED)
40          {
41              if (a.key.equals(s))
42              {
43                  return a;
44              }
45          }
46          return new ApplicationKey(s);
47      }
48      
49      /**
50       * Returns the string key used for this application in the Marketplace API.
51       */
52      public String getKey()
53      {
54          return key;
55      }
56  
57      @Override
58      public boolean equals(Object other)
59      {
60          if (other instanceof ApplicationKey)
61          {
62              return key.equals(((ApplicationKey) other).key);
63          }
64          return false;
65      }
66      
67      @Override
68      public int hashCode()
69      {
70          return key.hashCode();
71      }
72      
73      @Override
74      public String toString()
75      {
76          return "ApplicationKey(" + key + ")";
77      }
78  }