View Javadoc

1   package uk.ac.ebi.intenz.domain.enzyme;
2   
3   import uk.ac.ebi.intenz.domain.constants.EnzymeSourceConstant;
4   import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
5   import uk.ac.ebi.rhea.domain.Compound;
6   
7   
8   /**
9    * Cofactors are compounds participating in the reaction and are represented by this class.
10   * <p/>
11   * At the moment this class stores the cofactor string from ENZYME only. In future this string should
12   * be broken down into its components, i.e. compounds and the binary operators (AND/OR) between them.
13   * <p/>
14   * Instances of this class are immutable.
15   *
16   * @author Michael Darsow
17   * @version $Revision: 1.2 $ $Date: 2008/01/28 12:33:00 $
18   */
19  public class Cofactor implements Viewable {
20  
21  	public static enum Operators {
22   		/** Only used in complex nestings */
23   		AND("AND", "AND"),
24  	    /** For cofactors which can be used indiscriminately by an enzyme. */
25  		OR_OPTIONAL("OR", "OR1"),
26  	    /** For cofactors which are used by different families of enzymes within the same EC number. */
27   		OR_FAMILIES("OR", "OR2"),
28  	    /** For cofactors which may be used by an enzyme, but scientists aren't sure which one. */
29  		OR_UNKNOWN("OR", "OR3");
30  		private String text;
31  		private String code;
32  		private Operators(String t, String c){ this.text = t; this.code = c; }
33          @Override
34  		public String toString(){ return text; }
35  		public String getCode(){ return code; }
36  		public static String[] getCodes(){
37  			String[] result = new String[values().length];
38  			for (int i = 0; i < result.length; i++) {
39  				result[i] = values()[i].getCode();
40  			}
41  			return result;
42  		}
43  	}
44      
45    /**
46     * The string representation of the cofactor(s).
47     * @deprecated use compound.getName() instead
48     */
49    private String cofactorValue;
50  
51    private EnzymeSourceConstant source;
52  
53    private EnzymeViewConstant view;
54    
55    private Compound compound;
56  
57    /**
58     * Returns a <code>Cofactor</code> instance defined by <code>cofactorValue</code>.
59     *
60     * @param cofactorValue The string representation of the cofactor(s).
61     * @throws NullPointerException     if <code>cofactorValue</code> is <code>null</code>.
62     * @throws IllegalArgumentException if <code>cofactorValue</code> is empty.
63     * @deprecated use the valueOf method instead to call the private constructor
64     */
65    public Cofactor(String cofactorValue, EnzymeSourceConstant source, EnzymeViewConstant view) {
66      if (cofactorValue == null) throw new NullPointerException("Parameter 'cofactorValue' must not be null.");
67      if (cofactorValue.equals("")) throw new IllegalArgumentException("Parameter 'cofactorValue' must not be empty.");
68      if (source == null) throw new NullPointerException("Parameter 'source' must not be null.");
69      if (view == null) throw new NullPointerException("Parameter 'view' must not be null.");
70      this.cofactorValue = cofactorValue;
71      this.source = source;
72      this.view = view;
73    }
74    
75    private Cofactor(Compound compound, EnzymeSourceConstant source,
76            EnzymeViewConstant view) {
77        this.compound = compound;
78        this.source = source;
79        this.view = view;
80    }
81    
82    /**
83     * Builds a cofactor from the passed parameters.
84     * @param compound
85     * @param source
86     * @param view
87     * @return a new cofactor object
88     */
89      public static Cofactor valueOf(Compound compound, EnzymeSourceConstant source,
90              EnzymeViewConstant view) {
91          if (compound == null)
92              throw new NullPointerException("null compound");
93          if (source == null)
94              throw new NullPointerException("null source");
95          if (view == null)
96              throw new NullPointerException("null view");
97          return new Cofactor(compound, source, view);
98      }
99  
100   /**
101    * Standard equals method.
102    *
103    * @param o Object to be compared to this one.
104    * @return <code>true</code> if the objects are equal.
105    */
106     @Override
107   public boolean equals(Object o) {
108     if (this == o) return true;
109     if (!(o instanceof Cofactor)) return false;
110 
111     final Cofactor cofactor = (Cofactor) o;
112 
113     if (!compound.equals(cofactor.compound))
114         return false;
115     if (source != null ? !source.equals(cofactor.source) : cofactor.source != null)
116         return false;
117     if (view != null ? !view.equals(cofactor.view) : cofactor.view != null) 
118        return false;
119 
120     return true;
121   }
122 
123   /**
124    * Returns the hash code of this object.
125    *
126    * @return the hash code of this object.
127    */
128     @Override
129   public int hashCode() {
130     int result;
131     result = (compound != null ? compound.hashCode() : 0);
132     result = 29 * result + (source != null ? source.hashCode() : 0);
133     result = 29 * result + (view != null ? view.hashCode() : 0);
134     return result;
135   }
136 
137   
138   // ----------------  GETTER -----------------------------------
139 
140   /**
141    * Returns the cofactor string.
142    *
143    * @return the cofactor string.
144    * @deprecated use {@link #getCompound()}.getName() or {@link #toString()} instead
145    */
146   public String getCofactorValue() {
147     return cofactorValue;
148   }
149 
150   public EnzymeSourceConstant getSource() {
151       return source;
152   }
153 
154   public EnzymeViewConstant getView() {
155     return view;
156   }
157 
158     public Compound getCompound() {
159         return compound;
160     }
161 
162 	@Override
163 	public String toString() {
164 		return compound.toString();
165 	}
166 
167 }