1a8620e3103f866bab7ad4e4d830b8121dd47351
[vamsas.git] / src / uk / ac / vamsas / objects / core / Treenode.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  * node identity and mapping data between tree\r
19  *  representations and vamsas document objects \r
20  * \r
21  * @version $Revision$ $Date$\r
22  */\r
23 public class Treenode extends uk.ac.vamsas.objects.core.NodeType \r
24 implements java.io.Serializable\r
25 {\r
26 \r
27 \r
28       //--------------------------/\r
29      //- Class/Member Variables -/\r
30     //--------------------------/\r
31 \r
32     /**\r
33      * reference to one or more trees containing\r
34      *  the node being described. \r
35      */\r
36     private java.util.Vector _treeId;\r
37 \r
38     /**\r
39      * String uniquely identifying a particular\r
40      *  node in the referenced tree according to the format of\r
41      *  the tree representation that is referenced.\r
42      *  \r
43      */\r
44     private java.lang.String _nodespec;\r
45 \r
46 \r
47       //----------------/\r
48      //- Constructors -/\r
49     //----------------/\r
50 \r
51     public Treenode() {\r
52         super();\r
53         this._treeId = new java.util.Vector();\r
54     }\r
55 \r
56 \r
57       //-----------/\r
58      //- Methods -/\r
59     //-----------/\r
60 \r
61     /**\r
62      * \r
63      * \r
64      * @param vTreeId\r
65      * @throws java.lang.IndexOutOfBoundsException if the index\r
66      * given is outside the bounds of the collection\r
67      */\r
68     public void addTreeId(\r
69             final java.lang.Object vTreeId)\r
70     throws java.lang.IndexOutOfBoundsException {\r
71         this._treeId.addElement(vTreeId);\r
72     }\r
73 \r
74     /**\r
75      * \r
76      * \r
77      * @param index\r
78      * @param vTreeId\r
79      * @throws java.lang.IndexOutOfBoundsException if the index\r
80      * given is outside the bounds of the collection\r
81      */\r
82     public void addTreeId(\r
83             final int index,\r
84             final java.lang.Object vTreeId)\r
85     throws java.lang.IndexOutOfBoundsException {\r
86         this._treeId.add(index, vTreeId);\r
87     }\r
88 \r
89     /**\r
90      * Method enumerateTreeId.\r
91      * \r
92      * @return an Enumeration over all java.lang.Object elements\r
93      */\r
94     public java.util.Enumeration enumerateTreeId(\r
95     ) {\r
96         return this._treeId.elements();\r
97     }\r
98 \r
99     /**\r
100      * Overrides the java.lang.Object.equals method.\r
101      * \r
102      * @param obj\r
103      * @return true if the objects are equal.\r
104      */\r
105     public boolean equals(\r
106             final java.lang.Object obj) {\r
107         if ( this == obj )\r
108             return true;\r
109         \r
110         if (super.equals(obj)==false)\r
111             return false;\r
112         \r
113         if (obj instanceof Treenode) {\r
114         \r
115             Treenode temp = (Treenode)obj;\r
116             boolean thcycle;\r
117             boolean tmcycle;\r
118             if (this._treeId != null) {\r
119                 if (temp._treeId == null) return false;\r
120                 if (this._treeId != temp._treeId) {\r
121                     thcycle=org.castor.util.CycleBreaker.startingToCycle(this._treeId);\r
122                     tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._treeId);\r
123                     if (thcycle!=tmcycle) {\r
124                         if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._treeId); };\r
125                         if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._treeId); };\r
126                         return false;\r
127                     }\r
128                     if (!thcycle) {\r
129                         if (!this._treeId.equals(temp._treeId)) {\r
130                             org.castor.util.CycleBreaker.releaseCycleHandle(this._treeId);\r
131                             org.castor.util.CycleBreaker.releaseCycleHandle(temp._treeId);\r
132                             return false;\r
133                         }\r
134                         org.castor.util.CycleBreaker.releaseCycleHandle(this._treeId);\r
135                         org.castor.util.CycleBreaker.releaseCycleHandle(temp._treeId);\r
136                     }\r
137                 }\r
138             } else if (temp._treeId != null)\r
139                 return false;\r
140             if (this._nodespec != null) {\r
141                 if (temp._nodespec == null) return false;\r
142                 if (this._nodespec != temp._nodespec) {\r
143                     thcycle=org.castor.util.CycleBreaker.startingToCycle(this._nodespec);\r
144                     tmcycle=org.castor.util.CycleBreaker.startingToCycle(temp._nodespec);\r
145                     if (thcycle!=tmcycle) {\r
146                         if (!thcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(this._nodespec); };\r
147                         if (!tmcycle) { org.castor.util.CycleBreaker.releaseCycleHandle(temp._nodespec); };\r
148                         return false;\r
149                     }\r
150                     if (!thcycle) {\r
151                         if (!this._nodespec.equals(temp._nodespec)) {\r
152                             org.castor.util.CycleBreaker.releaseCycleHandle(this._nodespec);\r
153                             org.castor.util.CycleBreaker.releaseCycleHandle(temp._nodespec);\r
154                             return false;\r
155                         }\r
156                         org.castor.util.CycleBreaker.releaseCycleHandle(this._nodespec);\r
157                         org.castor.util.CycleBreaker.releaseCycleHandle(temp._nodespec);\r
158                     }\r
159                 }\r
160             } else if (temp._nodespec != null)\r
161                 return false;\r
162             return true;\r
163         }\r
164         return false;\r
165     }\r
166 \r
167     /**\r
168      * Returns the value of field 'nodespec'. The field 'nodespec'\r
169      * has the following description: String uniquely identifying a\r
170      * particular\r
171      *  node in the referenced tree according to the format of\r
172      *  the tree representation that is referenced.\r
173      *  \r
174      * \r
175      * @return the value of field 'Nodespec'.\r
176      */\r
177     public java.lang.String getNodespec(\r
178     ) {\r
179         return this._nodespec;\r
180     }\r
181 \r
182     /**\r
183      * Method getTreeId.\r
184      * \r
185      * @param index\r
186      * @throws java.lang.IndexOutOfBoundsException if the index\r
187      * given is outside the bounds of the collection\r
188      * @return the value of the java.lang.Object at the given index\r
189      */\r
190     public java.lang.Object getTreeId(\r
191             final int index)\r
192     throws java.lang.IndexOutOfBoundsException {\r
193         // check bounds for index\r
194         if (index < 0 || index >= this._treeId.size()) {\r
195             throw new IndexOutOfBoundsException("getTreeId: Index value '" + index + "' not in range [0.." + (this._treeId.size() - 1) + "]");\r
196         }\r
197         \r
198         return _treeId.get(index);\r
199     }\r
200 \r
201     /**\r
202      * Method getTreeId.Returns the contents of the collection in\r
203      * an Array.  <p>Note:  Just in case the collection contents\r
204      * are changing in another thread, we pass a 0-length Array of\r
205      * the correct type into the API call.  This way we <i>know</i>\r
206      * that the Array returned is of exactly the correct length.\r
207      * \r
208      * @return this collection as an Array\r
209      */\r
210     public java.lang.Object[] getTreeId(\r
211     ) {\r
212         java.lang.Object[] array = new java.lang.Object[0];\r
213         return (java.lang.Object[]) this._treeId.toArray(array);\r
214     }\r
215 \r
216     /**\r
217      * Method getTreeIdAsReference.Returns a reference to\r
218      * '_treeId'. No type checking is performed on any\r
219      * modifications to the Vector.\r
220      * \r
221      * @return a reference to the Vector backing this class\r
222      */\r
223     public java.util.Vector getTreeIdAsReference(\r
224     ) {\r
225         return this._treeId;\r
226     }\r
227 \r
228     /**\r
229      * Method getTreeIdCount.\r
230      * \r
231      * @return the size of this collection\r
232      */\r
233     public int getTreeIdCount(\r
234     ) {\r
235         return this._treeId.size();\r
236     }\r
237 \r
238     /**\r
239      * Overrides the java.lang.Object.hashCode method.\r
240      * <p>\r
241      * The following steps came from <b>Effective Java Programming\r
242      * Language Guide</b> by Joshua Bloch, Chapter 3\r
243      * \r
244      * @return a hash code value for the object.\r
245      */\r
246     public int hashCode(\r
247     ) {\r
248         int result = super.hashCode();\r
249         \r
250         long tmp;\r
251         if (_treeId != null\r
252             && !org.castor.util.CycleBreaker.startingToCycle(_treeId)) {\r
253            result = 37 * result + _treeId.hashCode();\r
254            org.castor.util.CycleBreaker.releaseCycleHandle(_treeId);\r
255         }\r
256         if (_nodespec != null\r
257             && !org.castor.util.CycleBreaker.startingToCycle(_nodespec)) {\r
258            result = 37 * result + _nodespec.hashCode();\r
259            org.castor.util.CycleBreaker.releaseCycleHandle(_nodespec);\r
260         }\r
261         \r
262         return result;\r
263     }\r
264 \r
265     /**\r
266      * Method isValid.\r
267      * \r
268      * @return true if this object is valid according to the schema\r
269      */\r
270     public boolean isValid(\r
271     ) {\r
272         try {\r
273             validate();\r
274         } catch (org.exolab.castor.xml.ValidationException vex) {\r
275             return false;\r
276         }\r
277         return true;\r
278     }\r
279 \r
280     /**\r
281      * \r
282      * \r
283      * @param out\r
284      * @throws org.exolab.castor.xml.MarshalException if object is\r
285      * null or if any SAXException is thrown during marshaling\r
286      * @throws org.exolab.castor.xml.ValidationException if this\r
287      * object is an invalid instance according to the schema\r
288      */\r
289     public void marshal(\r
290             final java.io.Writer out)\r
291     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {\r
292         Marshaller.marshal(this, out);\r
293     }\r
294 \r
295     /**\r
296      * \r
297      * \r
298      * @param handler\r
299      * @throws java.io.IOException if an IOException occurs during\r
300      * marshaling\r
301      * @throws org.exolab.castor.xml.ValidationException if this\r
302      * object is an invalid instance according to the schema\r
303      * @throws org.exolab.castor.xml.MarshalException if object is\r
304      * null or if any SAXException is thrown during marshaling\r
305      */\r
306     public void marshal(\r
307             final org.xml.sax.ContentHandler handler)\r
308     throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {\r
309         Marshaller.marshal(this, handler);\r
310     }\r
311 \r
312     /**\r
313      */\r
314     public void removeAllTreeId(\r
315     ) {\r
316         this._treeId.clear();\r
317     }\r
318 \r
319     /**\r
320      * Method removeTreeId.\r
321      * \r
322      * @param vTreeId\r
323      * @return true if the object was removed from the collection.\r
324      */\r
325     public boolean removeTreeId(\r
326             final java.lang.Object vTreeId) {\r
327         boolean removed = _treeId.remove(vTreeId);\r
328         return removed;\r
329     }\r
330 \r
331     /**\r
332      * Method removeTreeIdAt.\r
333      * \r
334      * @param index\r
335      * @return the element removed from the collection\r
336      */\r
337     public java.lang.Object removeTreeIdAt(\r
338             final int index) {\r
339         java.lang.Object obj = this._treeId.remove(index);\r
340         return obj;\r
341     }\r
342 \r
343     /**\r
344      * Sets the value of field 'nodespec'. The field 'nodespec' has\r
345      * the following description: String uniquely identifying a\r
346      * particular\r
347      *  node in the referenced tree according to the format of\r
348      *  the tree representation that is referenced.\r
349      *  \r
350      * \r
351      * @param nodespec the value of field 'nodespec'.\r
352      */\r
353     public void setNodespec(\r
354             final java.lang.String nodespec) {\r
355         this._nodespec = nodespec;\r
356     }\r
357 \r
358     /**\r
359      * \r
360      * \r
361      * @param index\r
362      * @param vTreeId\r
363      * @throws java.lang.IndexOutOfBoundsException if the index\r
364      * given is outside the bounds of the collection\r
365      */\r
366     public void setTreeId(\r
367             final int index,\r
368             final java.lang.Object vTreeId)\r
369     throws java.lang.IndexOutOfBoundsException {\r
370         // check bounds for index\r
371         if (index < 0 || index >= this._treeId.size()) {\r
372             throw new IndexOutOfBoundsException("setTreeId: Index value '" + index + "' not in range [0.." + (this._treeId.size() - 1) + "]");\r
373         }\r
374         \r
375         this._treeId.set(index, vTreeId);\r
376     }\r
377 \r
378     /**\r
379      * \r
380      * \r
381      * @param vTreeIdArray\r
382      */\r
383     public void setTreeId(\r
384             final java.lang.Object[] vTreeIdArray) {\r
385         //-- copy array\r
386         _treeId.clear();\r
387         \r
388         for (int i = 0; i < vTreeIdArray.length; i++) {\r
389                 this._treeId.add(vTreeIdArray[i]);\r
390         }\r
391     }\r
392 \r
393     /**\r
394      * Sets the value of '_treeId' by copying the given Vector. All\r
395      * elements will be checked for type safety.\r
396      * \r
397      * @param vTreeIdList the Vector to copy.\r
398      */\r
399     public void setTreeId(\r
400             final java.util.Vector vTreeIdList) {\r
401         // copy vector\r
402         this._treeId.clear();\r
403         \r
404         this._treeId.addAll(vTreeIdList);\r
405     }\r
406 \r
407     /**\r
408      * Sets the value of '_treeId' by setting it to the given\r
409      * Vector. No type checking is performed.\r
410      * @deprecated\r
411      * \r
412      * @param treeIdVector the Vector to set.\r
413      */\r
414     public void setTreeIdAsReference(\r
415             final java.util.Vector treeIdVector) {\r
416         this._treeId = treeIdVector;\r
417     }\r
418 \r
419     /**\r
420      * Method unmarshal.\r
421      * \r
422      * @param reader\r
423      * @throws org.exolab.castor.xml.MarshalException if object is\r
424      * null or if any SAXException is thrown during marshaling\r
425      * @throws org.exolab.castor.xml.ValidationException if this\r
426      * object is an invalid instance according to the schema\r
427      * @return the unmarshaled uk.ac.vamsas.objects.core.NodeType\r
428      */\r
429     public static uk.ac.vamsas.objects.core.NodeType unmarshal(\r
430             final java.io.Reader reader)\r
431     throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {\r
432         return (uk.ac.vamsas.objects.core.NodeType) Unmarshaller.unmarshal(uk.ac.vamsas.objects.core.Treenode.class, reader);\r
433     }\r
434 \r
435     /**\r
436      * \r
437      * \r
438      * @throws org.exolab.castor.xml.ValidationException if this\r
439      * object is an invalid instance according to the schema\r
440      */\r
441     public void validate(\r
442     )\r
443     throws org.exolab.castor.xml.ValidationException {\r
444         org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
445         validator.validate(this);\r
446     }\r
447 \r
448 }\r