View Javadoc
1   package com.atlassian.activeobjects.config;
2   
3   import org.apache.commons.lang3.builder.EqualsBuilder;
4   import org.apache.commons.lang3.builder.HashCodeBuilder;
5   import org.osgi.framework.Bundle;
6   
7   import static com.google.common.base.Preconditions.checkNotNull;
8   
9   /**
10   * <p>Represents a key used throughout the ActiveObjects plugin to store information
11   * about configuration etc. against each plugin using an {@link com.atlassian.activeobjects.external.ActiveObjects}
12   * service.</p>
13   * <p>So are {@link #equals(Object)} and {@link #hashCode()} as this class can be used and IS used as
14   * key in Maps and other such collections.</p>
15   */
16  public final class PluginKey {
17      private final String bundleSymbolicName;
18  
19      PluginKey(String bundleSymbolicName) {
20          this.bundleSymbolicName = checkNotNull(bundleSymbolicName);
21      }
22  
23      public static PluginKey fromBundle(Bundle bundle) {
24          checkNotNull(bundle);
25          return new PluginKey(bundle.getSymbolicName());
26      }
27  
28      public String asString() {
29          return bundleSymbolicName;
30      }
31  
32      @Override
33      public String toString() {
34          return asString();
35      }
36  
37      @Override
38      public int hashCode() {
39          return new HashCodeBuilder(3, 11).append(bundleSymbolicName).toHashCode();
40      }
41  
42      @Override
43      public boolean equals(Object o) {
44          if (o == null) {
45              return false;
46          }
47          if (o == this) {
48              return true;
49          }
50          if (o.getClass() != getClass()) {
51              return false;
52          }
53  
54          final PluginKey pluginKey = (PluginKey) o;
55          return new EqualsBuilder().append(bundleSymbolicName, pluginKey.bundleSymbolicName).isEquals();
56      }
57  }