View Javadoc

1   /*
2    * Created by IntelliJ IDEA.
3    * User: Mike
4    * Date: Jul 29, 2004
5    * Time: 3:19:33 PM
6    */
7   package com.atlassian.plugin;
8   
9   import org.apache.commons.lang.StringUtils;
10  
11  public class ModuleCompleteKey
12  {
13      private static final String SEPARATOR = ":";
14  
15      private final String pluginKey;
16      private final String moduleKey;
17  
18      public ModuleCompleteKey(String completeKey)
19      {
20          this(StringUtils.substringBefore(completeKey, SEPARATOR), StringUtils.substringAfter(completeKey, SEPARATOR));
21      }
22  
23      public ModuleCompleteKey(String pluginKey, String moduleKey)
24      {
25          this.pluginKey = StringUtils.trimToEmpty(pluginKey);
26  
27          if (!isValidKey(this.pluginKey))
28          {
29              throw new IllegalArgumentException("Invalid plugin key specified: " + this.pluginKey);
30          }
31  
32          this.moduleKey = StringUtils.trimToEmpty(moduleKey);
33  
34          if (!isValidKey(this.moduleKey))
35          {
36              throw new IllegalArgumentException("Invalid module key specified: " + this.moduleKey);
37          }
38      }
39  
40      private boolean isValidKey(String key)
41      {
42          return StringUtils.isNotBlank(key) && !key.contains(SEPARATOR);
43      }
44  
45      public String getModuleKey()
46      {
47          return moduleKey;
48      }
49  
50      public String getPluginKey()
51      {
52          return pluginKey;
53      }
54  
55      public String getCompleteKey()
56      {
57          return pluginKey + SEPARATOR + moduleKey;
58      }
59  
60      @Override
61      public boolean equals(Object o)
62      {
63          if (this == o) return true;
64          if (o == null || getClass() != o.getClass()) return false;
65  
66          ModuleCompleteKey that = (ModuleCompleteKey) o;
67  
68          if (!moduleKey.equals(that.moduleKey)) return false;
69          if (!pluginKey.equals(that.pluginKey)) return false;
70  
71          return true;
72      }
73  
74      @Override
75      public int hashCode()
76      {
77          int result = pluginKey.hashCode();
78          result = 31 * result + moduleKey.hashCode();
79          return result;
80      }
81  
82      @Override
83      public String toString()
84      {
85          return getCompleteKey();
86      }
87  }