b6c544c39c509329074563c447351badc2e42880
[vamsas.git] / src / uk / ac / vamsas / objects / core / AlignmentAnnotation.java
1 /*\r
2  * This class was automatically generated with \r
3  * <a href="http://www.castor.org">Castor 1.1</a>, using an XML\r
4  * Schema.\r
5  * $Id$\r
6  */\r
7 \r
8 package uk.ac.vamsas.objects.core;\r
9 \r
10   //---------------------------------/\r
11  //- Imported classes and packages -/\r
12 //---------------------------------/\r
13 \r
14 import org.exolab.castor.xml.Marshaller;\r
15 import org.exolab.castor.xml.Unmarshaller;\r
16 \r
17 /**\r
18  * This is annotation over the coordinate frame\r
19  *  defined by all the columns in the alignment.\r
20  *  \r
21  * \r
22  * @version $Revision$ $Date$\r
23  */\r
24 public class AlignmentAnnotation extends uk.ac.vamsas.objects.core.RangeAnnotation \r
25 implements java.io.Serializable\r
26 {\r
27 \r
28 \r
29       //--------------------------/\r
30      //- Class/Member Variables -/\r
31     //--------------------------/\r
32 \r
33     /**\r
34      * TODO: decide if this flag is\r
35      *  redundant - when true it would suggest that\r
36      *  the annotationElement values together form a\r
37      *  graph \r
38      */\r
39     private boolean _graph;\r
40 \r
41     /**\r
42      * keeps track of state for field: _graph\r
43      */\r
44     private boolean _has_graph;\r
45 \r
46     /**\r
47      * annotation is associated with\r
48      *  a range on a particular group of alignment\r
49      *  sequences\r
50      */\r
51     private java.util.Vector _seqrefs;\r
52 \r
53     /**\r
54      * Field _provenance.\r
55      */\r
56     private uk.ac.vamsas.objects.core.Provenance _provenance;\r
57 \r
58 \r
59       //----------------/\r
60      //- Constructors -/\r
61     //----------------/\r
62 \r
63     public AlignmentAnnotation() {\r
64         super();\r
65         this._seqrefs = new java.util.Vector();\r
66     }\r
67 \r
68 \r
69       //-----------/\r
70      //- Methods -/\r
71     //-----------/\r
72 \r
73     /**\r
74      * \r
75      * \r
76      * @param vSeqrefs\r
77      * @throws java.lang.IndexOutOfBoundsException if the index\r
78      * given is outside the bounds of the collection\r
79      */\r
80     public void addSeqrefs(\r
81             final java.lang.Object vSeqrefs)\r
82     throws java.lang.IndexOutOfBoundsException {\r
83         this._seqrefs.addElement(vSeqrefs);\r
84     }\r
85 \r
86     /**\r
87      * \r
88      * \r
89      * @param index\r
90      * @param vSeqrefs\r
91      * @throws java.lang.IndexOutOfBoundsException if the index\r
92      * given is outside the bounds of the collection\r
93      */\r
94     public void addSeqrefs(\r
95             final int index,\r
96             final java.lang.Object vSeqrefs)\r
97     throws java.lang.IndexOutOfBoundsException {\r
98         this._seqrefs.add(index, vSeqrefs);\r
99     }\r
100 \r
101     /**\r
102      */\r
103     public void deleteGraph(\r
104     ) {\r
105         this._has_graph= false;\r
106     }\r
107 \r
108     /**\r
109      * Method enumerateSeqrefs.\r
110      * \r
111      * @return an Enumeration over all java.lang.Object elements\r
112      */\r
113     public java.util.Enumeration enumerateSeqrefs(\r
114     ) {\r
115         return this._seqrefs.elements();\r
116     }\r
117 \r
118     /**\r
119      * Overrides the java.lang.Object.equals method.\r
120      * \r
121      * @param obj\r
122      * @return true if the objects are equal.\r
123      */\r
124     public boolean equals(\r
125             final java.lang.Object obj) {\r
126         if ( this == obj )\r
127             return true;\r
128         \r
129         if (super.equals(obj)==false)\r
130             return false;\r
131         \r
132         if (obj instanceof AlignmentAnnotation) {\r
133         \r
134             AlignmentAnnotation temp = (AlignmentAnnotation)obj;\r
135             boolean thcycle;\r
136             boolean tmcycle;\r
137             if (this._graph != temp._graph)\r
138                 return false;\r
139             if (this._has_graph != temp._has_graph)\r
140                 return false;\r
141             if (this._seqrefs != null) {\r
142                 if (temp._seqrefs == null) return false;\r
143                 if (this._seqrefs != temp._seqrefs) {\r
144                     thcycle=org.castor.util.CycleBreaker.startingToCycle(this._seqrefs);\r
145                     tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._seqrefs);\r
146                     if (thcycle!=tmcycle) {\r
147                         if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._seqrefs); };\r
148                         if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._seqrefs); };\r
149                         return false;\r
150                     }\r
151                     if (!thcycle) {\r
152                         if (!this._seqrefs.equals(temp._seqrefs)) {\r
153                             org.castor.util.CycleBreaker.releaseCycleHandle(this._seqrefs);\r
154                             org.castor.util.CycleBreaker.releaseCycleHandle(temp._seqrefs);\r
155                             return false;\r
156                         }\r
157                         org.castor.util.CycleBreaker.releaseCycleHandle(this._seqrefs);\r
158                         org.castor.util.CycleBreaker.releaseCycleHandle(temp._seqrefs);\r
159                     }\r
160                 }\r
161             } else if (temp._seqrefs != null)\r
162                 return false;\r
163             if (this._provenance != null) {\r
164                 if (temp._provenance == null) return false;\r
165                 if (this._provenance != temp._provenance) {\r
166                     thcycle=org.castor.util.CycleBreaker.startingToCycle(this._provenance);\r
167                     tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._provenance);\r
168                     if (thcycle!=tmcycle) {\r
169                         if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance); };\r
170                         if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance); };\r
171                         return false;\r
172                     }\r
173                     if (!thcycle) {\r
174                         if (!this._provenance.equals(temp._provenance)) {\r
175                             org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);\r
176                             org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);\r
177                             return false;\r
178                         }\r
179                         org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);\r
180                         org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);\r
181                     }\r
182                 }\r
183             } else if (temp._provenance != null)\r
184                 return false;\r
185             return true;\r
186         }\r
187         return false;\r
188     }\r
189 \r
190     /**\r
191      * Returns the value of field 'graph'. The field 'graph' has\r
192      * the following description: TODO: decide if this flag is\r
193      *  redundant - when true it would suggest that\r
194      *  the annotationElement values together form a\r
195      *  graph \r
196      * \r
197      * @return the value of field 'Graph'.\r
198      */\r
199     public boolean getGraph(\r
200     ) {\r
201         return this._graph;\r
202     }\r
203 \r
204     /**\r
205      * Returns the value of field 'provenance'.\r
206      * \r
207      * @return the value of field 'Provenance'.\r
208      */\r
209     public uk.ac.vamsas.objects.core.Provenance getProvenance(\r
210     ) {\r
211         return this._provenance;\r
212     }\r
213 \r
214     /**\r
215      * Method getSeqrefs.\r
216      * \r
217      * @param index\r
218      * @throws java.lang.IndexOutOfBoundsException if the index\r
219      * given is outside the bounds of the collection\r
220      * @return the value of the java.lang.Object at the given index\r
221      */\r
222     public java.lang.Object getSeqrefs(\r
223             final int index)\r
224     throws java.lang.IndexOutOfBoundsException {\r
225         // check bounds for index\r
226         if (index < 0 || index >= this._seqrefs.size()) {\r
227             throw new IndexOutOfBoundsException("getSeqrefs: Index value '" + index + "' not in range [0.." + (this._seqrefs.size() - 1) + "]");\r
228         }\r
229         \r
230         return _seqrefs.get(index);\r
231     }\r
232 \r
233     /**\r
234      * Method getSeqrefs.Returns the contents of the collection in\r
235      * an Array.  <p>Note:  Just in case the collection contents\r
236      * are changing in another thread, we pass a 0-length Array of\r
237      * the correct type into the API call.  This way we <i>know</i>\r
238      * that the Array returned is of exactly the correct length.\r
239      * \r
240      * @return this collection as an Array\r
241      */\r
242     public java.lang.Object[] getSeqrefs(\r
243     ) {\r
244         java.lang.Object[] array = new java.lang.Object[0];\r
245         return (java.lang.Object[]) this._seqrefs.toArray(array);\r
246     }\r
247 \r
248     /**\r
249      * Method getSeqrefsAsReference.Returns a reference to\r
250      * '_seqrefs'. No type checking is performed on any\r
251      * modifications to the Vector.\r
252      * \r
253      * @return a reference to the Vector backing this class\r
254      */\r
255     public java.util.Vector getSeqrefsAsReference(\r
256     ) {\r
257         return this._seqrefs;\r
258     }\r
259 \r
260     /**\r
261      * Method getSeqrefsCount.\r
262      * \r
263      * @return the size of this collection\r
264      */\r
265     public int getSeqrefsCount(\r
266     ) {\r
267         return this._seqrefs.size();\r
268     }\r
269 \r
270     /**\r
271      * Method hasGraph.\r
272      * \r
273      * @return true if at least one Graph has been added\r
274      */\r
275     public boolean hasGraph(\r
276     ) {\r
277         return this._has_graph;\r
278     }\r
279 \r
280     /**\r
281      * Overrides the java.lang.Object.hashCode method.\r
282      * <p>\r
283      * The following steps came from <b>Effective Java Programming\r
284      * Language Guide</b> by Joshua Bloch, Chapter 3\r
285      * \r
286      * @return a hash code value for the object.\r
287      */\r
288     public int hashCode(\r
289     ) {\r
290         int result = super.hashCode();\r
291         \r
292         long tmp;\r
293         result = 37 * result + (_graph?0:1);\r
294         if (_seqrefs != null\r
295             && !org.castor.util.CycleBreaker.startingToCycle(_seqrefs)) {\r
296            result = 37 * result + _seqrefs.hashCode();\r
297            org.castor.util.CycleBreaker.releaseCycleHandle(_seqrefs);\r
298         }\r
299         if (_provenance != null\r
300             && !org.castor.util.CycleBreaker.startingToCycle(_provenance)) {\r
301            result = 37 * result + _provenance.hashCode();\r
302            org.castor.util.CycleBreaker.releaseCycleHandle(_provenance);\r
303         }\r
304         \r
305         return result;\r
306     }\r
307 \r
308     /**\r
309      * Returns the value of field 'graph'. The field 'graph' has\r
310      * the following description: TODO: decide if this flag is\r
311      *  redundant - when true it would suggest that\r
312      *  the annotationElement values together form a\r
313      *  graph \r
314      * \r
315      * @return the value of field 'Graph'.\r
316      */\r
317     public boolean isGraph(\r
318     ) {\r
319         return this._graph;\r
320     }\r
321 \r
322     /**\r
323      * Method isValid.\r
324      * \r
325      * @return true if this object is valid according to the schema\r
326      */\r
327     public boolean isValid(\r
328     ) {\r
329         try {\r
330             validate();\r
331         } catch (org.exolab.castor.xml.ValidationException vex) {\r
332             return false;\r
333         }\r
334         return true;\r
335     }\r
336 \r
337     /**\r
338      * \r
339      * \r
340      * @param out\r
341      * @throws org.exolab.castor.xml.MarshalException if object is\r
342      * null or if any SAXException is thrown during marshaling\r
343      * @throws org.exolab.castor.xml.ValidationException if this\r
344      * object is an invalid instance according to the schema\r
345      */\r
346     public void marshal(\r
347             final java.io.Writer out)\r
348     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {\r
349         Marshaller.marshal(this, out);\r
350     }\r
351 \r
352     /**\r
353      * \r
354      * \r
355      * @param handler\r
356      * @throws java.io.IOException if an IOException occurs during\r
357      * marshaling\r
358      * @throws org.exolab.castor.xml.ValidationException if this\r
359      * object is an invalid instance according to the schema\r
360      * @throws org.exolab.castor.xml.MarshalException if object is\r
361      * null or if any SAXException is thrown during marshaling\r
362      */\r
363     public void marshal(\r
364             final org.xml.sax.ContentHandler handler)\r
365     throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {\r
366         Marshaller.marshal(this, handler);\r
367     }\r
368 \r
369     /**\r
370      */\r
371     public void removeAllSeqrefs(\r
372     ) {\r
373         this._seqrefs.clear();\r
374     }\r
375 \r
376     /**\r
377      * Method removeSeqrefs.\r
378      * \r
379      * @param vSeqrefs\r
380      * @return true if the object was removed from the collection.\r
381      */\r
382     public boolean removeSeqrefs(\r
383             final java.lang.Object vSeqrefs) {\r
384         boolean removed = _seqrefs.remove(vSeqrefs);\r
385         return removed;\r
386     }\r
387 \r
388     /**\r
389      * Method removeSeqrefsAt.\r
390      * \r
391      * @param index\r
392      * @return the element removed from the collection\r
393      */\r
394     public java.lang.Object removeSeqrefsAt(\r
395             final int index) {\r
396         java.lang.Object obj = this._seqrefs.remove(index);\r
397         return obj;\r
398     }\r
399 \r
400     /**\r
401      * Sets the value of field 'graph'. The field 'graph' has the\r
402      * following description: TODO: decide if this flag is\r
403      *  redundant - when true it would suggest that\r
404      *  the annotationElement values together form a\r
405      *  graph \r
406      * \r
407      * @param graph the value of field 'graph'.\r
408      */\r
409     public void setGraph(\r
410             final boolean graph) {\r
411         this._graph = graph;\r
412         this._has_graph = true;\r
413     }\r
414 \r
415     /**\r
416      * Sets the value of field 'provenance'.\r
417      * \r
418      * @param provenance the value of field 'provenance'.\r
419      */\r
420     public void setProvenance(\r
421             final uk.ac.vamsas.objects.core.Provenance provenance) {\r
422         this._provenance = provenance;\r
423     }\r
424 \r
425     /**\r
426      * \r
427      * \r
428      * @param index\r
429      * @param vSeqrefs\r
430      * @throws java.lang.IndexOutOfBoundsException if the index\r
431      * given is outside the bounds of the collection\r
432      */\r
433     public void setSeqrefs(\r
434             final int index,\r
435             final java.lang.Object vSeqrefs)\r
436     throws java.lang.IndexOutOfBoundsException {\r
437         // check bounds for index\r
438         if (index < 0 || index >= this._seqrefs.size()) {\r
439             throw new IndexOutOfBoundsException("setSeqrefs: Index value '" + index + "' not in range [0.." + (this._seqrefs.size() - 1) + "]");\r
440         }\r
441         \r
442         this._seqrefs.set(index, vSeqrefs);\r
443     }\r
444 \r
445     /**\r
446      * \r
447      * \r
448      * @param vSeqrefsArray\r
449      */\r
450     public void setSeqrefs(\r
451             final java.lang.Object[] vSeqrefsArray) {\r
452         //-- copy array\r
453         _seqrefs.clear();\r
454         \r
455         for (int i = 0; i < vSeqrefsArray.length; i++) {\r
456                 this._seqrefs.add(vSeqrefsArray[i]);\r
457         }\r
458     }\r
459 \r
460     /**\r
461      * Sets the value of '_seqrefs' by copying the given Vector.\r
462      * All elements will be checked for type safety.\r
463      * \r
464      * @param vSeqrefsList the Vector to copy.\r
465      */\r
466     public void setSeqrefs(\r
467             final java.util.Vector vSeqrefsList) {\r
468         // copy vector\r
469         this._seqrefs.clear();\r
470         \r
471         this._seqrefs.addAll(vSeqrefsList);\r
472     }\r
473 \r
474     /**\r
475      * Sets the value of '_seqrefs' by setting it to the given\r
476      * Vector. No type checking is performed.\r
477      * @deprecated\r
478      * \r
479      * @param seqrefsVector the Vector to set.\r
480      */\r
481     public void setSeqrefsAsReference(\r
482             final java.util.Vector seqrefsVector) {\r
483         this._seqrefs = seqrefsVector;\r
484     }\r
485 \r
486     /**\r
487      * Method unmarshal.\r
488      * \r
489      * @param reader\r
490      * @throws org.exolab.castor.xml.MarshalException if object is\r
491      * null or if any SAXException is thrown during marshaling\r
492      * @throws org.exolab.castor.xml.ValidationException if this\r
493      * object is an invalid instance according to the schema\r
494      * @return the unmarshaled uk.ac.vamsas.objects.core.RangeType\r
495      */\r
496     public static uk.ac.vamsas.objects.core.RangeType unmarshal(\r
497             final java.io.Reader reader)\r
498     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {\r
499         return (uk.ac.vamsas.objects.core.RangeType) Unmarshaller.unmarshal(uk.ac.vamsas.objects.core.AlignmentAnnotation.class, reader);\r
500     }\r
501 \r
502     /**\r
503      * \r
504      * \r
505      * @throws org.exolab.castor.xml.ValidationException if this\r
506      * object is an invalid instance according to the schema\r
507      */\r
508     public void validate(\r
509     )\r
510     throws org.exolab.castor.xml.ValidationException {\r
511         org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
512         validator.validate(this);\r
513     }\r
514 \r
515 }\r