View Javadoc

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