View Javadoc

1   package uk.ac.ebi.intenz.domain.enzyme;
2   
3   import uk.ac.ebi.intenz.domain.constants.EnzymeNameQualifierConstant;
4   import uk.ac.ebi.intenz.domain.constants.EnzymeNameTypeConstant;
5   import uk.ac.ebi.intenz.domain.constants.EnzymeSourceConstant;
6   import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
7   
8   /**
9    * This class stores a name related to an enzyme.
10   * <p/>
11   * Currently three different types of names are supported:
12   * <p/>
13   * <ol>
14   * <li>common (recommended) name</li>
15   * <li>systematic name</li>
16   * <li>synonym</li>
17   * </ol>
18   * <p/>
19   * Synonyms can be qualified and ordered.
20   * <p/>
21   * Instances of this class are immutable.
22   *
23   * @author Michael Darsow
24   * @version $Revision: 1.2 $ $Date: 2008/01/28 12:33:00 $
25   */
26  public class EnzymeName implements Comparable<EnzymeName>, Viewable {
27  
28    public static EnzymeName UNDEF = new EnzymeName("", EnzymeNameTypeConstant.UNDEF, EnzymeNameQualifierConstant.UNDEF,
29                                                    EnzymeSourceConstant.UNDEF, EnzymeViewConstant.UNDEF);
30  
31    private String name;
32  
33    private EnzymeNameTypeConstant type;
34  
35    private EnzymeNameQualifierConstant qualifier;
36  
37    private EnzymeSourceConstant source;
38  
39    private EnzymeViewConstant view;
40  
41  
42    /**
43     * Object cannot be created outside this class.
44     *
45     * @param name      A name of an enzyme.
46     * @param type      The type of an enzyme's name (see {@link uk.ac.ebi.intenz.domain.constants.EnzymeNameTypeConstant}).
47     * @param qualifier A qualifier used for synonyms (see {@link uk.ac.ebi.intenz.domain.constants.EnzymeNameQualifierConstant}).
48     */
49    private EnzymeName(String name, EnzymeNameTypeConstant type, EnzymeNameQualifierConstant qualifier,
50                       EnzymeSourceConstant source, EnzymeViewConstant view) {
51      this.name = name;
52      this.type = type;
53      this.qualifier = qualifier;
54      this.source = source;
55      this.view = view;
56    }
57  
58    public static EnzymeName valueOf(String name, EnzymeNameTypeConstant type, EnzymeNameQualifierConstant qualifier,
59                                     EnzymeSourceConstant source, EnzymeViewConstant view) {
60      if (type == EnzymeNameTypeConstant.COMMON_NAME) return getCommonNameInstance(name, source, view);
61      if (type == EnzymeNameTypeConstant.SYSTEMATIC_NAME) return getSystematicNameInstance(name, source, view);
62      if (type == EnzymeNameTypeConstant.OTHER_NAME) return getSynonymInstance(name, qualifier, source, view);
63      throw new IllegalArgumentException("The given type is not supported.");
64    }
65  
66    /**
67     * Returns an <code>EnzymeName</code> instance representing an enzyme's common (recommended) name.
68     *
69     * @param name The common name.
70     * @return The <code>EnzymeName</code> instance representing the common name.
71     * @throws NullPointerException     if <code>name</code> is <code>null</code>.
72     * @throws IllegalArgumentException if <code>name</code> is empty.
73     */
74    public static EnzymeName getCommonNameInstance(String name, EnzymeSourceConstant source, EnzymeViewConstant view) {
75      if (name == null) throw new NullPointerException("Parameter 'name' must not be null.");
76      if (source == null) throw new NullPointerException("Parameter 'source' must not be null.");
77      if (view == null) throw new NullPointerException("Parameter 'view' must not be null.");
78      if (name.equals("")) throw new IllegalArgumentException("Parameter 'name' must not be empty.");
79  
80      return new EnzymeName(name, EnzymeNameTypeConstant.COMMON_NAME,
81                            EnzymeNameQualifierConstant.UNDEF, source, view);
82    }
83  
84    /**
85     * Returns an <code>EnzymeName</code> instance representing an enzyme's systematic name.
86     *
87     * @param name The systematic name.
88     * @return The <code>EnzymeName</code> instance representing the systematic name.
89     * @throws NullPointerException     if <code>name</code> is <code>null</code>.
90     * @throws IllegalArgumentException if <code>name</code> is empty.
91     */
92    public static EnzymeName getSystematicNameInstance(String name, EnzymeSourceConstant source, EnzymeViewConstant view) {
93      if (name == null) throw new NullPointerException("Parameter 'name' must not be null.");
94      if (source == null) throw new NullPointerException("Parameter 'source' must not be null.");
95      if (view == null) throw new NullPointerException("Parameter 'view' must not be null.");
96      if (name.equals("")) throw new IllegalArgumentException("Parameter 'name' must not be empty.");
97  
98      return new EnzymeName(name, EnzymeNameTypeConstant.SYSTEMATIC_NAME,
99                            EnzymeNameQualifierConstant.UNDEF, source, view);
100   }
101 
102   /**
103    * Returns an <code>EnzymeName</code> instance representing an enzyme's synonym.
104    *
105    * @param name      The systematic name.
106    * @param qualifier A qualifier used for synonyms (see {@link uk.ac.ebi.intenz.domain.constants.EnzymeNameQualifierConstant}).
107    * @return The <code>EnzymeName</code> instance representing the synonym.
108    * @throws NullPointerException     if <code>name</code> or <code>qualifier</code> are <code>null</code>.
109    * @throws IllegalArgumentException if <code>name</code> is empty or <code>orderIn</code> is < 1.
110    */
111   public static EnzymeName getSynonymInstance(String name, EnzymeNameQualifierConstant qualifier,
112                                               EnzymeSourceConstant source, EnzymeViewConstant view) {
113     if (name == null) throw new NullPointerException("Parameter 'name' must not be null.");
114     if (qualifier == null) throw new NullPointerException("Parameter 'qualifier' must not be null.");
115     if (source == null) throw new NullPointerException("Parameter 'source' must not be null.");
116     if (view == null) throw new NullPointerException("Parameter 'view' must not be null.");
117     if (name.equals("")) throw new IllegalArgumentException("Parameter 'name' must not be empty.");
118 
119     return new EnzymeName(name, EnzymeNameTypeConstant.OTHER_NAME, qualifier, source, view);
120   }
121 
122   /**
123    * @param name The specified enzyme name.
124    * @return a neg. integer if this instance is smaller than the specified name 0 if they are equal and a pos. integer otherwise.
125    */
126   public int compareTo(EnzymeName name) {
127     int result = name.getSource().toString().compareTo(source.toString());
128     if (result == 0) {
129       return (name.getName().compareTo(this.name));
130     }
131     return result;
132   }
133 
134   /**
135    * Standard equals method omitting 'orderIn' attribute, which is irrelevant for this check.
136    *
137    * @param o Object to be compared to this one.
138    * @return <code>true</code> if the objects are equal.
139    */
140   public boolean equals(Object o) {
141     if (this == o) return true;
142     if (!(o instanceof EnzymeName)) return false;
143 
144     final EnzymeName enzymeName = (EnzymeName) o;
145 
146     if (name != null ? !name.equals(enzymeName.name) : enzymeName.name != null) return false;
147     if (qualifier != null ? !qualifier.equals(enzymeName.qualifier) : enzymeName.qualifier != null) return false;
148     if (source != null ? !source.equals(enzymeName.source) : enzymeName.source != null) return false;
149     if (type != null ? !type.equals(enzymeName.type) : enzymeName.type != null) return false;
150     if (view != null ? !view.equals(enzymeName.view) : enzymeName.view != null) return false;
151 
152     return true;
153   }
154 
155   /**
156    * Returns the hash code of this object.
157    *
158    * @return the hash code of this object.
159    */
160   public int hashCode() {
161     int result;
162     result = (name != null ? name.hashCode() : 0);
163     result = 29 * result + (type != null ? type.hashCode() : 0);
164     result = 29 * result + (qualifier != null ? qualifier.hashCode() : 0);
165     result = 29 * result + (source != null ? source.hashCode() : 0);
166     result = 29 * result + (view != null ? view.hashCode() : 0);
167     return result;
168   }
169 
170   // --------------------  GETTER -----------------------
171 
172   /**
173    * Returns the name.
174    *
175    * @return the name.
176    */
177   public String getName() {
178     return name;
179   }
180 
181   /**
182    * Returns the name's type.
183    *
184    * @return the name's type.
185    * @see EnzymeNameTypeConstant
186    */
187   public EnzymeNameTypeConstant getType() {
188     return type;
189   }
190 
191   /**
192    * Returns the name's qualifier.
193    *
194    * @return the name's qualifier.
195    * @see EnzymeNameQualifierConstant
196    */
197   public EnzymeNameQualifierConstant getQualifier() {
198     return qualifier;
199   }
200 
201   /**
202    * Returns the name's source.
203    *
204    * @return the name's source.
205    * @see EnzymeSourceConstant
206    */
207   public EnzymeSourceConstant getSource() {
208     return source;
209   }
210 
211   /**
212    * Returns the name's view code.
213    * <p/>
214    * The code defines in which view this name will be displayed.
215    *
216    * @return the name's view code.
217    * @see EnzymeViewConstant
218    */
219   public EnzymeViewConstant getView() {
220     return view;
221   }
222 
223   // ------------------- PRIVATE METHODS ------------------------
224 }