View Javadoc
1   package uk.ac.ebi.intenz.domain.constants;
2   
3   /**
4    * This class represents an enumeration of all database source types.
5    * <p/>
6    * Instances of this class are immutable.
7    *
8    * @author Michael Darsow
9    * @version $Revision: 1.2 $ $Date: 2008/01/28 12:33:06 $
10   */
11  public class EnzymeNameTypeConstant {
12    private final String nameTypeCode;
13  
14    public static final EnzymeNameTypeConstant UNDEF = new EnzymeNameTypeConstant("NON");
15    public static final EnzymeNameTypeConstant COMMON_NAME = new EnzymeNameTypeConstant("COM");
16    public static final EnzymeNameTypeConstant SYSTEMATIC_NAME = new EnzymeNameTypeConstant("SYS");
17    public static final EnzymeNameTypeConstant OTHER_NAME = new EnzymeNameTypeConstant("OTH");
18  
19    /**
20     * Returns an <code>EnzymeNameTypeConstant</code> instance of the given type string.
21     *
22     * @param type The type string defining this instance.
23     * @return The <code>EnzymeNameTypeConstant</code> instance.
24     * @throws NullPointerException     if <code>type</code> is <code>null</code>.
25     * @throws IllegalArgumentException if <code>type</code> is unknown.
26     */
27    public static EnzymeNameTypeConstant valueOf(String type) {
28      if (type == null) throw new NullPointerException("Parameter 'type' must not be null.");
29  
30      if (type.equals(UNDEF.toString())) return UNDEF;
31      if (type.equals(COMMON_NAME.toString())) return COMMON_NAME;
32      if (type.equals(SYSTEMATIC_NAME.toString())) return SYSTEMATIC_NAME;
33      if (type.equals(OTHER_NAME.toString())) return OTHER_NAME;
34  	throw new IllegalArgumentException();
35    }
36  
37    /**
38     * Object cannot be created outside this class.
39     *
40     * @param nameTypeCode The line type code.
41     */
42    private EnzymeNameTypeConstant(String nameTypeCode) {
43      this.nameTypeCode = nameTypeCode;
44    }
45  
46    /**
47     * Standard equals method.
48     *
49     * @param o Object to be compared to this one.
50     * @return <code>true</code> if the objects are equal.
51     */
52    public boolean equals(Object o) {
53      if (this == o) return true;
54      if (!(o instanceof EnzymeNameTypeConstant)) return false;
55  
56      final EnzymeNameTypeConstant enzymeSource = (EnzymeNameTypeConstant) o;
57  
58      if (!nameTypeCode.equals(enzymeSource.nameTypeCode)) return false;
59  
60      return true;
61    }
62  
63    /**
64     * Returns the hash code of this object.
65     *
66     * @return the hash code of this object.
67     */
68    public int hashCode() {
69      return nameTypeCode.hashCode();
70    }
71  
72    /**
73     * Returns the database code.
74     *
75     * @return the database code.
76     */
77    public String toString() {
78      return nameTypeCode;
79    }
80  }
81  
82