View Javadoc

1   package uk.ac.ebi.intenz.domain.enzyme;
2   
3   import java.util.List;
4   
5   /**
6    * This class represents an enzyme class of the Enzyme Nomenclature.
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:00 $
12   */
13  public class EnzymeClass implements Comparable<EnzymeClass> {
14  
15    private EnzymeCommissionNumber ec;
16  
17    private String name;
18  
19    private String description;
20  
21    private List<EnzymeSubclass> subclasses;
22  
23    /**
24     * Returns an <code>EnzymeClass</code> instance.
25     *
26     * @param ec          The class' EC.
27     * @param name        The name of the class.
28     * @param description The description of the class.
29     * @param subclasses  The list of subclasses (see {@link EnzymeSubclass}).
30     */
31    private EnzymeClass(EnzymeCommissionNumber ec, String name, String description, List<EnzymeSubclass> subclasses) {
32      this.ec = ec;
33      this.name = name;
34      this.description = description;
35      this.subclasses = subclasses;
36    }
37  
38    /**
39     * Returns an <code>EnzymeClass</code> instance.
40     *
41     * @param ec          The class' EC.
42     * @param name        The name of the class.
43     * @param description The description of the class.
44     * @param subclasses  The list of subclasses (see {@link EnzymeSubclass}).
45     * @throws NullPointerException     if any parameter is <code>null</code>.
46     * @throws IllegalArgumentException if <code>name</code> or the list of subclasses is empty.
47     */
48    public static EnzymeClass valueOf(EnzymeCommissionNumber ec, String name, String description,
49  		  List<EnzymeSubclass> subclasses) {
50      if (ec == null || name == null || description == null || subclasses == null)
51        throw new NullPointerException("No parameter must be 'null'.");
52      if (name.equals("")) throw new IllegalArgumentException("A class must have a name.");
53      if (subclasses.size() == 0) throw new IllegalArgumentException("The list of subclasses must not be empty.");
54      return new EnzymeClass(ec, name, description, subclasses);
55    }
56  
57    /**
58     * Makes instances of this class comparable.
59     *
60     * @param enzymeClass The object to be compared to this instance.
61     * @return a pos. integer if this instance is greater than, a neg. integer if it is less than or 0 if it equals o.
62     */
63    public int compareTo(EnzymeClass enzymeClass) {
64      return ec.compareTo(enzymeClass.getEc());
65    }
66  
67    /**
68     * Standard equals method.
69     *
70     * @param o Object to be compared to this one.
71     * @return <code>true</code> if the objects are equal.
72     */
73    public boolean equals(Object o) {
74      if (this == o) return true;
75      if (!(o instanceof EnzymeClass)) return false;
76  
77      final EnzymeClass enzymeClass = (EnzymeClass) o;
78  
79      if (description != null ? !description.equals(enzymeClass.description) : enzymeClass.description != null) return false;
80      if (ec != null ? !ec.equals(enzymeClass.ec) : enzymeClass.ec != null) return false;
81      if (name != null ? !name.equals(enzymeClass.name) : enzymeClass.name != null) return false;
82      if (subclasses != null ? !subclasses.equals(enzymeClass.subclasses) : enzymeClass.subclasses != null) return false;
83  
84      return true;
85    }
86  
87    public int hashCode() {
88      int result;
89      result = (ec != null ? ec.hashCode() : 0);
90      result = 29 * result + (name != null ? name.hashCode() : 0);
91      result = 29 * result + (description != null ? description.hashCode() : 0);
92      result = 29 * result + (subclasses != null ? subclasses.hashCode() : 0);
93      return result;
94    }
95  
96    /**
97     * Returns the hash code of this object.
98     *
99     * @return the hash code of this object.
100    */
101 
102 
103 
104   // ----------------  GETTER  ------------------
105 
106   public EnzymeCommissionNumber getEc() {
107     return ec;
108   }
109 
110   public String getName() {
111     return name;
112   }
113 
114   public String getDescription() {
115     return description;
116   }
117 
118   public List<EnzymeSubclass> getSubclasses() {
119     return subclasses;
120   }
121 
122 }