applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / core / AlignmentSequenceAnnotation.java
1 /*\r
2  * This file is part of the Vamsas Client version 0.1. \r
3  * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, \r
4  *  Andrew Waterhouse and Dominik Lindner.\r
5  * \r
6  * Earlier versions have also been incorporated into Jalview version 2.4 \r
7  * since 2008, and TOPALi version 2 since 2007.\r
8  * \r
9  * The Vamsas Client is free software: you can redistribute it and/or modify\r
10  * it under the terms of the GNU Lesser General Public License as published by\r
11  * the Free Software Foundation, either version 3 of the License, or\r
12  * (at your option) any later version.\r
13  *  \r
14  * The Vamsas Client is distributed in the hope that it will be useful,\r
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
17  * GNU Lesser General Public License for more details.\r
18  * \r
19  * You should have received a copy of the GNU Lesser General Public License\r
20  * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.\r
21  */\r
22 package uk.ac.vamsas.objects.core;\r
23 \r
24 //---------------------------------/\r
25 //- Imported classes and packages -/\r
26 //---------------------------------/\r
27 \r
28 import org.exolab.castor.xml.Marshaller;\r
29 import org.exolab.castor.xml.Unmarshaller;\r
30 \r
31 /**\r
32  * Class AlignmentSequenceAnnotation.\r
33  * \r
34  * @version $Revision$ $Date$\r
35  */\r
36 public class AlignmentSequenceAnnotation extends\r
37     uk.ac.vamsas.objects.core.RangeAnnotation implements java.io.Serializable {\r
38 \r
39   // --------------------------/\r
40   // - Class/Member Variables -/\r
41   // --------------------------/\r
42 \r
43   /**\r
44    * TODO: decide if this flag is redundant - when true it would suggest that\r
45    * the annotationElement values together form a graph\r
46    * \r
47    */\r
48   private boolean _graph;\r
49 \r
50   /**\r
51    * keeps track of state for field: _graph\r
52    */\r
53   private boolean _has_graph;\r
54 \r
55   /**\r
56    * Field _provenance.\r
57    */\r
58   private uk.ac.vamsas.objects.core.Provenance _provenance;\r
59 \r
60   // ----------------/\r
61   // - Constructors -/\r
62   // ----------------/\r
63 \r
64   public AlignmentSequenceAnnotation() {\r
65     super();\r
66   }\r
67 \r
68   // -----------/\r
69   // - Methods -/\r
70   // -----------/\r
71 \r
72   /**\r
73      */\r
74   public void deleteGraph() {\r
75     this._has_graph = false;\r
76   }\r
77 \r
78   /**\r
79    * Overrides the java.lang.Object.equals method.\r
80    * \r
81    * @param obj\r
82    * @return true if the objects are equal.\r
83    */\r
84   public boolean equals(final java.lang.Object obj) {\r
85     if (this == obj)\r
86       return true;\r
87 \r
88     if (super.equals(obj) == false)\r
89       return false;\r
90 \r
91     if (obj instanceof AlignmentSequenceAnnotation) {\r
92 \r
93       AlignmentSequenceAnnotation temp = (AlignmentSequenceAnnotation) obj;\r
94       boolean thcycle;\r
95       boolean tmcycle;\r
96       if (this._graph != temp._graph)\r
97         return false;\r
98       if (this._has_graph != temp._has_graph)\r
99         return false;\r
100       if (this._provenance != null) {\r
101         if (temp._provenance == null)\r
102           return false;\r
103         if (this._provenance != temp._provenance) {\r
104           thcycle = org.castor.util.CycleBreaker\r
105               .startingToCycle(this._provenance);\r
106           tmcycle = org.castor.util.CycleBreaker\r
107               .startingToCycle(temp._provenance);\r
108           if (thcycle != tmcycle) {\r
109             if (!thcycle) {\r
110               org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);\r
111             }\r
112             ;\r
113             if (!tmcycle) {\r
114               org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);\r
115             }\r
116             ;\r
117             return false;\r
118           }\r
119           if (!thcycle) {\r
120             if (!this._provenance.equals(temp._provenance)) {\r
121               org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);\r
122               org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);\r
123               return false;\r
124             }\r
125             org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);\r
126             org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);\r
127           }\r
128         }\r
129       } else if (temp._provenance != null)\r
130         return false;\r
131       return true;\r
132     }\r
133     return false;\r
134   }\r
135 \r
136   /**\r
137    * Returns the value of field 'graph'. The field 'graph' has the following\r
138    * description: TODO: decide if this flag is redundant - when true it would\r
139    * suggest that the annotationElement values together form a graph\r
140    * \r
141    * \r
142    * @return the value of field 'Graph'.\r
143    */\r
144   public boolean getGraph() {\r
145     return this._graph;\r
146   }\r
147 \r
148   /**\r
149    * Returns the value of field 'provenance'.\r
150    * \r
151    * @return the value of field 'Provenance'.\r
152    */\r
153   public uk.ac.vamsas.objects.core.Provenance getProvenance() {\r
154     return this._provenance;\r
155   }\r
156 \r
157   /**\r
158    * Method hasGraph.\r
159    * \r
160    * @return true if at least one Graph has been added\r
161    */\r
162   public boolean hasGraph() {\r
163     return this._has_graph;\r
164   }\r
165 \r
166   /**\r
167    * Overrides the java.lang.Object.hashCode method.\r
168    * <p>\r
169    * The following steps came from <b>Effective Java Programming Language\r
170    * Guide</b> by Joshua Bloch, Chapter 3\r
171    * \r
172    * @return a hash code value for the object.\r
173    */\r
174   public int hashCode() {\r
175     int result = super.hashCode();\r
176 \r
177     long tmp;\r
178     result = 37 * result + (_graph ? 0 : 1);\r
179     if (_provenance != null\r
180         && !org.castor.util.CycleBreaker.startingToCycle(_provenance)) {\r
181       result = 37 * result + _provenance.hashCode();\r
182       org.castor.util.CycleBreaker.releaseCycleHandle(_provenance);\r
183     }\r
184 \r
185     return result;\r
186   }\r
187 \r
188   /**\r
189    * Returns the value of field 'graph'. The field 'graph' has the following\r
190    * description: TODO: decide if this flag is redundant - when true it would\r
191    * suggest that the annotationElement values together form a graph\r
192    * \r
193    * \r
194    * @return the value of field 'Graph'.\r
195    */\r
196   public boolean isGraph() {\r
197     return this._graph;\r
198   }\r
199 \r
200   /**\r
201    * Method isValid.\r
202    * \r
203    * @return true if this object is valid according to the schema\r
204    */\r
205   public boolean isValid() {\r
206     try {\r
207       validate();\r
208     } catch (org.exolab.castor.xml.ValidationException vex) {\r
209       return false;\r
210     }\r
211     return true;\r
212   }\r
213 \r
214   /**\r
215    * \r
216    * \r
217    * @param out\r
218    * @throws org.exolab.castor.xml.MarshalException\r
219    *           if object is null or if any SAXException is thrown during\r
220    *           marshaling\r
221    * @throws org.exolab.castor.xml.ValidationException\r
222    *           if this object is an invalid instance according to the schema\r
223    */\r
224   public void marshal(final java.io.Writer out)\r
225       throws org.exolab.castor.xml.MarshalException,\r
226       org.exolab.castor.xml.ValidationException {\r
227     Marshaller.marshal(this, out);\r
228   }\r
229 \r
230   /**\r
231    * \r
232    * \r
233    * @param handler\r
234    * @throws java.io.IOException\r
235    *           if an IOException occurs during marshaling\r
236    * @throws org.exolab.castor.xml.ValidationException\r
237    *           if this object is an invalid instance according to the schema\r
238    * @throws org.exolab.castor.xml.MarshalException\r
239    *           if object is null or if any SAXException is thrown during\r
240    *           marshaling\r
241    */\r
242   public void marshal(final org.xml.sax.ContentHandler handler)\r
243       throws java.io.IOException, org.exolab.castor.xml.MarshalException,\r
244       org.exolab.castor.xml.ValidationException {\r
245     Marshaller.marshal(this, handler);\r
246   }\r
247 \r
248   /**\r
249    * Sets the value of field 'graph'. The field 'graph' has the following\r
250    * description: TODO: decide if this flag is redundant - when true it would\r
251    * suggest that the annotationElement values together form a graph\r
252    * \r
253    * \r
254    * @param graph\r
255    *          the value of field 'graph'.\r
256    */\r
257   public void setGraph(final boolean graph) {\r
258     this._graph = graph;\r
259     this._has_graph = true;\r
260   }\r
261 \r
262   /**\r
263    * Sets the value of field 'provenance'.\r
264    * \r
265    * @param provenance\r
266    *          the value of field 'provenance'.\r
267    */\r
268   public void setProvenance(\r
269       final uk.ac.vamsas.objects.core.Provenance provenance) {\r
270     this._provenance = provenance;\r
271   }\r
272 \r
273   /**\r
274    * Method unmarshal.\r
275    * \r
276    * @param reader\r
277    * @throws org.exolab.castor.xml.MarshalException\r
278    *           if object is null or if any SAXException is thrown during\r
279    *           marshaling\r
280    * @throws org.exolab.castor.xml.ValidationException\r
281    *           if this object is an invalid instance according to the schema\r
282    * @return the unmarshaled uk.ac.vamsas.objects.core.RangeType\r
283    */\r
284   public static uk.ac.vamsas.objects.core.RangeType unmarshal(\r
285       final java.io.Reader reader)\r
286       throws org.exolab.castor.xml.MarshalException,\r
287       org.exolab.castor.xml.ValidationException {\r
288     return (uk.ac.vamsas.objects.core.RangeType) Unmarshaller.unmarshal(\r
289         uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation.class, reader);\r
290   }\r
291 \r
292   /**\r
293    * \r
294    * \r
295    * @throws org.exolab.castor.xml.ValidationException\r
296    *           if this object is an invalid instance according to the schema\r
297    */\r
298   public void validate() throws org.exolab.castor.xml.ValidationException {\r
299     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
300     validator.validate(this);\r
301   }\r
302 \r
303 }\r