View Javadoc

1   package uk.ac.ebi.intenz.domain.constants;
2   
3   
4   /**
5    * This class represents an enumeration of all database source types.
6    * <p/>
7    * Instances of this class are immutable.
8    *
9    * @author Michael Darsow
10   * @version $Revision: 1.3 $ $Date: 2009/04/16 15:01:04 $
11   * @deprecated use enumeration {@link Status} instead.
12   */
13  public class EnzymeStatusConstant {
14    private final String statusCode;
15  
16    private final String text;
17  
18    public static final EnzymeStatusConstant APPROVED = new EnzymeStatusConstant("OK", "approved");
19    public static final EnzymeStatusConstant SUGGESTED = new EnzymeStatusConstant("SU", "suggested");
20    public static final EnzymeStatusConstant PROPOSED = new EnzymeStatusConstant("PR", "proposed");
21  
22    /**
23     * Returns the corresponding instance of the given status code.
24     * <p/>
25     * If the status code does not match any code an exception is thrown.
26     *
27     * @param statusCode The status code.
28     * @return the class constant corresponding to the given code.
29     * @throws NullPointerException     if <code>statusCode</code> is <code>null</code>.
30     * @throws IllegalArgumentException if the code is invalid.
31     */
32    public static EnzymeStatusConstant valueOf(String statusCode) {
33      if (statusCode == null) throw new NullPointerException("Parameter 'statusCode' must not be null.");
34      if (statusCode.equals(APPROVED.getCode())) return APPROVED;
35      if (statusCode.equals(SUGGESTED.getCode())) return SUGGESTED;
36      if (statusCode.equals(PROPOSED.getCode())) return PROPOSED;
37  	throw new IllegalArgumentException("Parameter 'statusCode' is invalid.");
38    }
39  
40    /**
41     * Object cannot be created outside this class.
42     *
43     * @param statusCode The status code.
44     */
45    private EnzymeStatusConstant(String statusCode, String text) {
46      this.statusCode = statusCode;
47      this.text = text;
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 EnzymeStatusConstant)) return false;
59  
60      final EnzymeStatusConstant enzymeStatus = (EnzymeStatusConstant) o;
61  
62      if (statusCode != null ? !statusCode.equals(enzymeStatus.statusCode) : enzymeStatus.statusCode != null) return false;
63      if (text != null ? !text.equals(enzymeStatus.text) : enzymeStatus.text != null) return false;
64  
65      return true;
66    }
67  
68    /**
69     * Returns the hash code of this object.
70     *
71     * @return the hash code of this object.
72     */
73    public int hashCode() {
74      int result;
75      result = (statusCode != null ? statusCode.hashCode() : 0);
76      result = 29 * result + (text != null ? text.hashCode() : 0);
77      return result;
78    }
79  
80    /**
81     * Returns the status code's text.
82     *
83     * @return the status code's text.
84     */
85    public String toString() {
86      return text;
87    }
88  
89    /**
90     * Returns the status code.
91     *
92     * @return the status code.
93     */
94    public String getCode() {
95      return statusCode;
96    }
97  }
98  
99