View Javadoc

1   package uk.ac.ebi.intenz.domain.constants;
2   
3   
4   
5   /**
6    * This class represents an enumeration of all database source types.
7    * <p/>
8    * Instances of this class are immutable.
9    *
10   * @author Michael Darsow
11   * @version $Revision: 1.2 $ $Date: 2008/01/28 12:33:06 $
12   */
13  public class EnzymeSourceConstant {
14    private final String sourceCode;
15  
16    public static final EnzymeSourceConstant UNDEF = new EnzymeSourceConstant("UNDEF");
17    public static final EnzymeSourceConstant IUBMB = new EnzymeSourceConstant("IUBMB");
18    public static final EnzymeSourceConstant SIB = new EnzymeSourceConstant("SIB");
19    public static final EnzymeSourceConstant BRENDA = new EnzymeSourceConstant("BRENDA");
20    public static final EnzymeSourceConstant INTENZ = new EnzymeSourceConstant("INTENZ");
21  
22    /**
23     * Object cannot be created outside this class.
24     *
25     * @param sourceCode The line type code.
26     */
27    private EnzymeSourceConstant(String sourceCode) {
28      this.sourceCode = sourceCode;
29    }
30  
31    /**
32     * Returns the corresponding instance of the given source code.
33     * <p/>
34     * If the source code does not match any code an exception is thrown.
35     *
36     * @param sourceCode The source code.
37     * @return the class constant corresponding to the given code.
38     * @throws NullPointerException     if <code>sourceCode</code> is <code>null</code>.
39     * @throws IllegalArgumentException if the code is invalid.
40     */
41    public static EnzymeSourceConstant valueOf(String sourceCode) {
42      if (sourceCode == null) throw new NullPointerException("Parameter 'sourceCode' must not be null.");
43      if (sourceCode.equals(IUBMB.toString())) return IUBMB;
44      if (sourceCode.equals(SIB.toString())) return SIB;
45      if (sourceCode.equals(BRENDA.toString())) return BRENDA;
46      if (sourceCode.equals(INTENZ.toString())) return INTENZ;
47  	throw new IllegalArgumentException("The given source code is not supported.");
48    }
49  
50    /**
51     * Standard equals method.
52     *
53     * @param o Object to be compared to this one.
54     * @return <code>true</code> if the objects are equal.
55     */
56    public boolean equals(Object o) {
57      if (this == o) return true;
58      if (!(o instanceof EnzymeSourceConstant)) return false;
59  
60      final EnzymeSourceConstant enzymeSource = (EnzymeSourceConstant) o;
61  
62      if (!sourceCode.equals(enzymeSource.sourceCode)) return false;
63  
64      return true;
65    }
66  
67    /**
68     * Returns the hash code of this object.
69     *
70     * @return the hash code of this object.
71     */
72    public int hashCode() {
73      return sourceCode.hashCode();
74    }
75  
76    /**
77     * Returns the database code.
78     *
79     * @return the database code.
80     */
81    public String toString() {
82      return sourceCode;
83    }
84  
85    /**
86     * @deprecated
87     * @param source
88     * @return
89     */
90    public static String toDisplayString(String source) {
91      EnzymeSourceConstant sourceConstant = EnzymeSourceConstant.valueOf(source);
92      if(sourceConstant == UNDEF) return "undefined";
93      if(sourceConstant == IUBMB) return "NC-IUBMB";
94      if(sourceConstant == SIB) return "ENZYME";
95      if(sourceConstant == INTENZ) return "IntEnz";
96      return "BRENDA";
97    }
98  
99    /**
100    * @deprecated
101    * @return
102    */
103   public String toDisplayString() {
104     if(this == UNDEF) return "undefined";
105     if(this == IUBMB) return "NC-IUBMB";
106     if(this == SIB) return "ENZYME";
107     if(this == INTENZ) return "IntEnz";
108     return "BRENDA";
109   }
110 }
111 
112