1   package com.atlassian.user.repository;
2   
3   /**
4    * Default identifier class for a repository.
5    * <p/>
6    * Comparisons between different repositories are done with the key.
7    *
8    * @see #equals(Object)
9    */
10  public class DefaultRepositoryIdentifier implements RepositoryIdentifier
11  {
12      private final String key;
13      private final String name;
14  
15      /**
16       * Create a repository with the specified key.
17       *
18       * @param key the repository key, which must be unique and not <code>null</code>.
19       * @param name the name of the repository, which must not be <code>null</code>.
20       * @throws IllegalArgumentException if either key or name is <code>null</code>.
21       */
22      public DefaultRepositoryIdentifier(String key, String name)
23      {
24          if (key == null)
25              throw new IllegalArgumentException("Repository key cannot be null");
26          if (name == null)
27              throw new IllegalArgumentException("Repository name cannot be null");
28          this.key = key;
29          this.name = name;
30      }
31  
32      public String getName()
33      {
34          return name;
35      }
36  
37      public String getKey()
38      {
39          return key;
40      }
41  
42      /**
43       * Compares this repository with another repository, using the keys of both.
44       *
45       * @return true if the other object is a {@link RepositoryIdentifier} with an equal key, otherwise false.
46       */
47      public boolean equals(Object o)
48      {
49          if (this == o) return true;
50          if (!(o instanceof RepositoryIdentifier)) return false;
51  
52          final RepositoryIdentifier repo = (RepositoryIdentifier) o;
53          return key.equals(repo.getKey());
54      }
55  
56      public int hashCode()
57      {
58          return key.hashCode();
59      }
60  
61      public String toString()
62      {
63          return name;
64      }
65  }