fa91d515f270070fe1921d922ff3302c69710a15
[jalview.git] / src / jalview / schemabinding / version2 / VAMSAS.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  *  
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.schemabinding.version2;
19
20 //---------------------------------/
21 //- Imported classes and packages -/
22 //---------------------------------/
23
24 import org.exolab.castor.xml.Marshaller;
25 import org.exolab.castor.xml.Unmarshaller;
26
27 /**
28  * Class VAMSAS.
29  * 
30  * @version $Revision$ $Date$
31  */
32 public class VAMSAS implements java.io.Serializable
33 {
34
35   // --------------------------/
36   // - Class/Member Variables -/
37   // --------------------------/
38
39   /**
40    * Field _treeList.
41    */
42   private java.util.Vector _treeList;
43
44   /**
45    * Field _sequenceSetList.
46    */
47   private java.util.Vector _sequenceSetList;
48
49   // ----------------/
50   // - Constructors -/
51   // ----------------/
52
53   public VAMSAS()
54   {
55     super();
56     this._treeList = new java.util.Vector();
57     this._sequenceSetList = new java.util.Vector();
58   }
59
60   // -----------/
61   // - Methods -/
62   // -----------/
63
64   /**
65    * 
66    * 
67    * @param vSequenceSet
68    * @throws java.lang.IndexOutOfBoundsException
69    *           if the index given is outside the bounds of the collection
70    */
71   public void addSequenceSet(
72           final jalview.schemabinding.version2.SequenceSet vSequenceSet)
73           throws java.lang.IndexOutOfBoundsException
74   {
75     this._sequenceSetList.addElement(vSequenceSet);
76   }
77
78   /**
79    * 
80    * 
81    * @param index
82    * @param vSequenceSet
83    * @throws java.lang.IndexOutOfBoundsException
84    *           if the index given is outside the bounds of the collection
85    */
86   public void addSequenceSet(final int index,
87           final jalview.schemabinding.version2.SequenceSet vSequenceSet)
88           throws java.lang.IndexOutOfBoundsException
89   {
90     this._sequenceSetList.add(index, vSequenceSet);
91   }
92
93   /**
94    * 
95    * 
96    * @param vTree
97    * @throws java.lang.IndexOutOfBoundsException
98    *           if the index given is outside the bounds of the collection
99    */
100   public void addTree(final java.lang.String vTree)
101           throws java.lang.IndexOutOfBoundsException
102   {
103     this._treeList.addElement(vTree);
104   }
105
106   /**
107    * 
108    * 
109    * @param index
110    * @param vTree
111    * @throws java.lang.IndexOutOfBoundsException
112    *           if the index given is outside the bounds of the collection
113    */
114   public void addTree(final int index, final java.lang.String vTree)
115           throws java.lang.IndexOutOfBoundsException
116   {
117     this._treeList.add(index, vTree);
118   }
119
120   /**
121    * Method enumerateSequenceSet.
122    * 
123    * @return an Enumeration over all jalview.schemabinding.version2.SequenceSet
124    *         elements
125    */
126   public java.util.Enumeration enumerateSequenceSet()
127   {
128     return this._sequenceSetList.elements();
129   }
130
131   /**
132    * Method enumerateTree.
133    * 
134    * @return an Enumeration over all java.lang.String elements
135    */
136   public java.util.Enumeration enumerateTree()
137   {
138     return this._treeList.elements();
139   }
140
141   /**
142    * Method getSequenceSet.
143    * 
144    * @param index
145    * @throws java.lang.IndexOutOfBoundsException
146    *           if the index given is outside the bounds of the collection
147    * @return the value of the jalview.schemabinding.version2.SequenceSet at the
148    *         given index
149    */
150   public jalview.schemabinding.version2.SequenceSet getSequenceSet(
151           final int index) throws java.lang.IndexOutOfBoundsException
152   {
153     // check bounds for index
154     if (index < 0 || index >= this._sequenceSetList.size())
155     {
156       throw new IndexOutOfBoundsException("getSequenceSet: Index value '"
157               + index + "' not in range [0.."
158               + (this._sequenceSetList.size() - 1) + "]");
159     }
160
161     return (jalview.schemabinding.version2.SequenceSet) _sequenceSetList
162             .get(index);
163   }
164
165   /**
166    * Method getSequenceSet.Returns the contents of the collection in an Array.
167    * <p>
168    * Note: Just in case the collection contents are changing in another thread,
169    * we pass a 0-length Array of the correct type into the API call. This way we
170    * <i>know</i> that the Array returned is of exactly the correct length.
171    * 
172    * @return this collection as an Array
173    */
174   public jalview.schemabinding.version2.SequenceSet[] getSequenceSet()
175   {
176     jalview.schemabinding.version2.SequenceSet[] array = new jalview.schemabinding.version2.SequenceSet[0];
177     return (jalview.schemabinding.version2.SequenceSet[]) this._sequenceSetList
178             .toArray(array);
179   }
180
181   /**
182    * Method getSequenceSetCount.
183    * 
184    * @return the size of this collection
185    */
186   public int getSequenceSetCount()
187   {
188     return this._sequenceSetList.size();
189   }
190
191   /**
192    * Method getTree.
193    * 
194    * @param index
195    * @throws java.lang.IndexOutOfBoundsException
196    *           if the index given is outside the bounds of the collection
197    * @return the value of the java.lang.String at the given index
198    */
199   public java.lang.String getTree(final int index)
200           throws java.lang.IndexOutOfBoundsException
201   {
202     // check bounds for index
203     if (index < 0 || index >= this._treeList.size())
204     {
205       throw new IndexOutOfBoundsException("getTree: Index value '" + index
206               + "' not in range [0.." + (this._treeList.size() - 1) + "]");
207     }
208
209     return (java.lang.String) _treeList.get(index);
210   }
211
212   /**
213    * Method getTree.Returns the contents of the collection in an Array.
214    * <p>
215    * Note: Just in case the collection contents are changing in another thread,
216    * we pass a 0-length Array of the correct type into the API call. This way we
217    * <i>know</i> that the Array returned is of exactly the correct length.
218    * 
219    * @return this collection as an Array
220    */
221   public java.lang.String[] getTree()
222   {
223     java.lang.String[] array = new java.lang.String[0];
224     return (java.lang.String[]) this._treeList.toArray(array);
225   }
226
227   /**
228    * Method getTreeCount.
229    * 
230    * @return the size of this collection
231    */
232   public int getTreeCount()
233   {
234     return this._treeList.size();
235   }
236
237   /**
238    * Method isValid.
239    * 
240    * @return true if this object is valid according to the schema
241    */
242   public boolean isValid()
243   {
244     try
245     {
246       validate();
247     } catch (org.exolab.castor.xml.ValidationException vex)
248     {
249       return false;
250     }
251     return true;
252   }
253
254   /**
255    * 
256    * 
257    * @param out
258    * @throws org.exolab.castor.xml.MarshalException
259    *           if object is null or if any SAXException is thrown during
260    *           marshaling
261    * @throws org.exolab.castor.xml.ValidationException
262    *           if this object is an invalid instance according to the schema
263    */
264   public void marshal(final java.io.Writer out)
265           throws org.exolab.castor.xml.MarshalException,
266           org.exolab.castor.xml.ValidationException
267   {
268     Marshaller.marshal(this, out);
269   }
270
271   /**
272    * 
273    * 
274    * @param handler
275    * @throws java.io.IOException
276    *           if an IOException occurs during marshaling
277    * @throws org.exolab.castor.xml.ValidationException
278    *           if this object is an invalid instance according to the schema
279    * @throws org.exolab.castor.xml.MarshalException
280    *           if object is null or if any SAXException is thrown during
281    *           marshaling
282    */
283   public void marshal(final org.xml.sax.ContentHandler handler)
284           throws java.io.IOException,
285           org.exolab.castor.xml.MarshalException,
286           org.exolab.castor.xml.ValidationException
287   {
288     Marshaller.marshal(this, handler);
289   }
290
291   /**
292      */
293   public void removeAllSequenceSet()
294   {
295     this._sequenceSetList.clear();
296   }
297
298   /**
299      */
300   public void removeAllTree()
301   {
302     this._treeList.clear();
303   }
304
305   /**
306    * Method removeSequenceSet.
307    * 
308    * @param vSequenceSet
309    * @return true if the object was removed from the collection.
310    */
311   public boolean removeSequenceSet(
312           final jalview.schemabinding.version2.SequenceSet vSequenceSet)
313   {
314     boolean removed = _sequenceSetList.remove(vSequenceSet);
315     return removed;
316   }
317
318   /**
319    * Method removeSequenceSetAt.
320    * 
321    * @param index
322    * @return the element removed from the collection
323    */
324   public jalview.schemabinding.version2.SequenceSet removeSequenceSetAt(
325           final int index)
326   {
327     java.lang.Object obj = this._sequenceSetList.remove(index);
328     return (jalview.schemabinding.version2.SequenceSet) obj;
329   }
330
331   /**
332    * Method removeTree.
333    * 
334    * @param vTree
335    * @return true if the object was removed from the collection.
336    */
337   public boolean removeTree(final java.lang.String vTree)
338   {
339     boolean removed = _treeList.remove(vTree);
340     return removed;
341   }
342
343   /**
344    * Method removeTreeAt.
345    * 
346    * @param index
347    * @return the element removed from the collection
348    */
349   public java.lang.String removeTreeAt(final int index)
350   {
351     java.lang.Object obj = this._treeList.remove(index);
352     return (java.lang.String) obj;
353   }
354
355   /**
356    * 
357    * 
358    * @param index
359    * @param vSequenceSet
360    * @throws java.lang.IndexOutOfBoundsException
361    *           if the index given is outside the bounds of the collection
362    */
363   public void setSequenceSet(final int index,
364           final jalview.schemabinding.version2.SequenceSet vSequenceSet)
365           throws java.lang.IndexOutOfBoundsException
366   {
367     // check bounds for index
368     if (index < 0 || index >= this._sequenceSetList.size())
369     {
370       throw new IndexOutOfBoundsException("setSequenceSet: Index value '"
371               + index + "' not in range [0.."
372               + (this._sequenceSetList.size() - 1) + "]");
373     }
374
375     this._sequenceSetList.set(index, vSequenceSet);
376   }
377
378   /**
379    * 
380    * 
381    * @param vSequenceSetArray
382    */
383   public void setSequenceSet(
384           final jalview.schemabinding.version2.SequenceSet[] vSequenceSetArray)
385   {
386     // -- copy array
387     _sequenceSetList.clear();
388
389     for (int i = 0; i < vSequenceSetArray.length; i++)
390     {
391       this._sequenceSetList.add(vSequenceSetArray[i]);
392     }
393   }
394
395   /**
396    * 
397    * 
398    * @param index
399    * @param vTree
400    * @throws java.lang.IndexOutOfBoundsException
401    *           if the index given is outside the bounds of the collection
402    */
403   public void setTree(final int index, final java.lang.String vTree)
404           throws java.lang.IndexOutOfBoundsException
405   {
406     // check bounds for index
407     if (index < 0 || index >= this._treeList.size())
408     {
409       throw new IndexOutOfBoundsException("setTree: Index value '" + index
410               + "' not in range [0.." + (this._treeList.size() - 1) + "]");
411     }
412
413     this._treeList.set(index, vTree);
414   }
415
416   /**
417    * 
418    * 
419    * @param vTreeArray
420    */
421   public void setTree(final java.lang.String[] vTreeArray)
422   {
423     // -- copy array
424     _treeList.clear();
425
426     for (int i = 0; i < vTreeArray.length; i++)
427     {
428       this._treeList.add(vTreeArray[i]);
429     }
430   }
431
432   /**
433    * Method unmarshal.
434    * 
435    * @param reader
436    * @throws org.exolab.castor.xml.MarshalException
437    *           if object is null or if any SAXException is thrown during
438    *           marshaling
439    * @throws org.exolab.castor.xml.ValidationException
440    *           if this object is an invalid instance according to the schema
441    * @return the unmarshaled jalview.schemabinding.version2.VAMSAS
442    */
443   public static jalview.schemabinding.version2.VAMSAS unmarshal(
444           final java.io.Reader reader)
445           throws org.exolab.castor.xml.MarshalException,
446           org.exolab.castor.xml.ValidationException
447   {
448     return (jalview.schemabinding.version2.VAMSAS) Unmarshaller.unmarshal(
449             jalview.schemabinding.version2.VAMSAS.class, reader);
450   }
451
452   /**
453    * 
454    * 
455    * @throws org.exolab.castor.xml.ValidationException
456    *           if this object is an invalid instance according to the schema
457    */
458   public void validate() throws org.exolab.castor.xml.ValidationException
459   {
460     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
461     validator.validate(this);
462   }
463
464 }