View Javadoc

1   package uk.ac.ebi.intenz.domain.constants;
2   
3   /**
4    * This class represents an enumeration of all supported name qualifiers.
5    * <p/>
6    * Instances of this class are immutable.
7    *
8    * @author Michael Darsow
9    * @version $Revision: 1.3 $ $Date: 2009/04/16 15:01:04 $
10   */
11  public class EnzymeNameQualifierConstant {
12  
13    public static final EnzymeNameQualifierConstant UNDEF = new EnzymeNameQualifierConstant("NON");
14    public static final EnzymeNameQualifierConstant MISLEADING = new EnzymeNameQualifierConstant("MIS");
15    public static final EnzymeNameQualifierConstant AMBIGUOUS = new EnzymeNameQualifierConstant("AMB");
16    public static final EnzymeNameQualifierConstant OBSOLETE = new EnzymeNameQualifierConstant("OBS");
17    public static final EnzymeNameQualifierConstant MISPRINT = new EnzymeNameQualifierConstant("MPR");
18    public static final EnzymeNameQualifierConstant INCORRECT = new EnzymeNameQualifierConstant("INC");
19  
20    private String qualifier;
21  
22    /**
23     * Returns an <code>EnzymeNameQualifierConstant</code> instance of the given qualifier string.
24     *
25     * @param qualifier The qualifier string defining this instance.
26     * @return The <code>EnzymeNameQualifierConstant</code> instance.
27     * @throws NullPointerException     if <code>qualifier</code> is <code>null</code>.
28     * @throws IllegalArgumentException if <code>qualifier</code> is unknown.
29     */
30    public static EnzymeNameQualifierConstant valueOf(String qualifier) {
31      if (qualifier == null) throw new NullPointerException("Parameter 'qualifier' must not be null.");
32  
33      if (qualifier.equals(UNDEF.toString()) || qualifier.equals("")) return UNDEF;
34      if (qualifier.equals(MISLEADING.toString())) return MISLEADING;
35      if (qualifier.equals(AMBIGUOUS.toString())) return AMBIGUOUS;
36      if (qualifier.equals(OBSOLETE.toString())) return OBSOLETE;
37      if (qualifier.equals(MISPRINT.toString())) return MISPRINT;
38      if (qualifier.equals(INCORRECT.toString())) return INCORRECT;
39  	throw new IllegalArgumentException();
40    }
41  
42    /**
43     * Object cannot be created outside this class.
44     *
45     * @param qualifier The name qualifier.
46     */
47    private EnzymeNameQualifierConstant(String qualifier) {
48      this.qualifier = qualifier;
49    }
50  
51    /**
52     * Standard equals method.
53     *
54     * @param o Object to be compared to this one.
55     * @return <code>true</code> if the objects are equal.
56     */
57    public boolean equals(Object o) {
58      if (this == o) return true;
59      if (!(o instanceof EnzymeNameQualifierConstant)) return false;
60  
61      final EnzymeNameQualifierConstant enzymeNameQualifierConstant = (EnzymeNameQualifierConstant) o;
62  
63      if (qualifier != null ? !qualifier.equals(enzymeNameQualifierConstant.qualifier) : enzymeNameQualifierConstant.qualifier != 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      return (qualifier != null ? qualifier.hashCode() : 0);
75    }
76  
77    /**
78     * Returns the name qualifier.
79     *
80     * @return the name qualifier.
81     */
82    public String toString() {
83      return qualifier;
84    }
85  
86     /**
87     * TODO: put somewhere else.
88     * Returns the human readable representation of the qualifier in ASCII flat file form.
89     *
90     * @param name The name is used to construct the URL for the ambiguous name search.
91     * @return the human readable representation.
92     * @deprecated
93     */
94    public String toASCII(EnzymeNameQualifierConstant name) {
95      if(this == MISLEADING) return "[misleading]";
96      if(this == OBSOLETE) return "[obsolete]";
97      if(this == AMBIGUOUS) return "[ambiguous]";
98      if(this == MISPRINT) return "[misprint]";
99      if(this == INCORRECT) return "[incorrect]";
100     return "";
101   }
102 
103   /**
104    * TODO: put somewhere else.
105    * Returns the human readable representation of the qualifier in HTML.
106    *
107    * @param name The name is used to construct the URL for the ambiguous name search.
108    * @return the human readable representation.
109    * @deprecated MVC sin
110    */
111   public String toHTML(String name) {
112     if(this == MISLEADING) return "[misleading]";
113     if(this == OBSOLETE) return "[obsolete]";
114     if(this == AMBIGUOUS) return "[<a href=\"search.do?q="+name+"\">ambiguous</a>]";
115     if(this == MISPRINT) return "[misprint]";
116     if(this == INCORRECT) return "[incorrect]";
117     return "";
118   }
119   
120   public String getLabel(){
121 	  if(this == MISLEADING) return "misleading";
122 	  if(this == OBSOLETE) return "obsolete";
123 	  if(this == AMBIGUOUS) return "ambiguous";
124 	  if(this == MISPRINT) return "misprint";
125 	  if(this == INCORRECT) return "incorrect";
126 	  return null;
127   }
128 
129   /**
130    * TODO: put somewhere else
131    * Returns an editable representation of the qualifier in HTML.
132    *
133    * @return the human readable representation.
134    * @deprecated MVC sin
135    */
136   public String toEditableHTML() {
137     StringBuffer html = new StringBuffer();
138 
139     html.append("Additional characteristic:\n<select name=\"characteristics\" size=\"1\">\n");
140     html.append(getEditableHTML());
141     html.append("</select>\n");
142 
143     return html.toString();
144   }
145 
146   /**
147    * TODO: put somewhere else
148    * Returns a string containing editable HTML.
149    *
150    * @return a string containing editable HTML.
151    * @deprecated MVC sin
152    */
153   private String getEditableHTML() {
154     StringBuffer html = new StringBuffer();
155 
156     if(this == UNDEF) {
157       html.append("<option selected=\"selected\" value=\"NON\">&lt;NONE&gt;</option>");
158       html.append("<option value=\"MIS\">misleading</option>");
159       html.append("<option value=\"OBS\">obsolete</option>");
160       html.append("<option value=\"AMB\">ambiguous</option>");
161       html.append("<option value=\"MPR\">misprint</option>");
162       html.append("<option value=\"INC\">incorrect</option>");
163     }
164 
165     if(this == MISLEADING) {
166       html.append("<option selected=\"selected\" value=\"MIS\">misleading</option>");
167       html.append("<option value=\"NON\">&lt;NONE&gt;</option>");
168       html.append("<option value=\"OBS\">obsolete</option>");
169       html.append("<option value=\"AMB\">ambiguous</option>");
170       html.append("<option value=\"MPR\">misprint</option>");
171       html.append("<option value=\"INC\">incorrect</option>");
172     }
173 
174     if(this == OBSOLETE) {
175       html.append("<option selected=\"selected\" value=\"OBS\">obsolete</option>");
176       html.append("<option value=\"NON\">&lt;NONE&gt;</option>");
177       html.append("<option value=\"MIS\">misleading</option>");
178       html.append("<option value=\"AMB\">ambiguous</option>");
179       html.append("<option value=\"MPR\">misprint</option>");
180       html.append("<option value=\"INC\">incorrect</option>");
181     }
182 
183     if(this == AMBIGUOUS) {
184       html.append("<option selected=\"selected\" value=\"AMB\">ambiguous</option>");
185       html.append("<option value=\"NON\">&lt;NONE&gt;</option>");
186       html.append("<option value=\"MIS\">misleading</option>");
187       html.append("<option value=\"OBS\">obsolete</option>");
188       html.append("<option value=\"MPR\">misprint</option>");
189       html.append("<option value=\"INC\">incorrect</option>");
190     }
191 
192     if(this == MISPRINT) {
193       html.append("<option selected=\"selected\" value=\"AMB\">ambiguous</option>");
194       html.append("<option value=\"NON\">&lt;NONE&gt;</option>");
195       html.append("<option value=\"MIS\">misleading</option>");
196       html.append("<option value=\"AMB\">ambiguous</option>");
197       html.append("<option value=\"OBS\">obsolete</option>");
198       html.append("<option value=\"INC\">incorrect</option>");
199     }
200 
201     if(this == INCORRECT) {
202       html.append("<option selected=\"selected\" value=\"AMB\">ambiguous</option>");
203       html.append("<option value=\"NON\">&lt;NONE&gt;</option>");
204       html.append("<option value=\"MIS\">misleading</option>");
205       html.append("<option value=\"AMB\">ambiguous</option>");
206       html.append("<option value=\"OBS\">obsolete</option>");
207       html.append("<option value=\"MPR\">misprint</option>");
208     }
209 
210     return html.toString();
211   }
212 }
213 
214