7856de9dc3c83ac5c5ccc6161676b083d53971c5
[jalview.git] / src / jalview / binding / 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.binding;
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 _alignmentList.
41    */
42   private java.util.Vector _alignmentList;
43
44   /**
45    * Field _treeList.
46    */
47   private java.util.Vector _treeList;
48
49   /**
50    * Field _sequenceSetList.
51    */
52   private java.util.Vector _sequenceSetList;
53
54   // ----------------/
55   // - Constructors -/
56   // ----------------/
57
58   public VAMSAS()
59   {
60     super();
61     this._alignmentList = new java.util.Vector();
62     this._treeList = new java.util.Vector();
63     this._sequenceSetList = new java.util.Vector();
64   }
65
66   // -----------/
67   // - Methods -/
68   // -----------/
69
70   /**
71    * 
72    * 
73    * @param vAlignment
74    * @throws java.lang.IndexOutOfBoundsException
75    *           if the index given is outside the bounds of the collection
76    */
77   public void addAlignment(final Alignment vAlignment)
78           throws java.lang.IndexOutOfBoundsException
79   {
80     this._alignmentList.addElement(vAlignment);
81   }
82
83   /**
84    * 
85    * 
86    * @param index
87    * @param vAlignment
88    * @throws java.lang.IndexOutOfBoundsException
89    *           if the index given is outside the bounds of the collection
90    */
91   public void addAlignment(final int index, final Alignment vAlignment)
92           throws java.lang.IndexOutOfBoundsException
93   {
94     this._alignmentList.add(index, vAlignment);
95   }
96
97   /**
98    * 
99    * 
100    * @param vSequenceSet
101    * @throws java.lang.IndexOutOfBoundsException
102    *           if the index given is outside the bounds of the collection
103    */
104   public void addSequenceSet(final SequenceSet vSequenceSet)
105           throws java.lang.IndexOutOfBoundsException
106   {
107     this._sequenceSetList.addElement(vSequenceSet);
108   }
109
110   /**
111    * 
112    * 
113    * @param index
114    * @param vSequenceSet
115    * @throws java.lang.IndexOutOfBoundsException
116    *           if the index given is outside the bounds of the collection
117    */
118   public void addSequenceSet(final int index, final SequenceSet vSequenceSet)
119           throws java.lang.IndexOutOfBoundsException
120   {
121     this._sequenceSetList.add(index, vSequenceSet);
122   }
123
124   /**
125    * 
126    * 
127    * @param vTree
128    * @throws java.lang.IndexOutOfBoundsException
129    *           if the index given is outside the bounds of the collection
130    */
131   public void addTree(final java.lang.String vTree)
132           throws java.lang.IndexOutOfBoundsException
133   {
134     this._treeList.addElement(vTree);
135   }
136
137   /**
138    * 
139    * 
140    * @param index
141    * @param vTree
142    * @throws java.lang.IndexOutOfBoundsException
143    *           if the index given is outside the bounds of the collection
144    */
145   public void addTree(final int index, final java.lang.String vTree)
146           throws java.lang.IndexOutOfBoundsException
147   {
148     this._treeList.add(index, vTree);
149   }
150
151   /**
152    * Method enumerateAlignment.
153    * 
154    * @return an Enumeration over all Alignment elements
155    */
156   public java.util.Enumeration enumerateAlignment()
157   {
158     return this._alignmentList.elements();
159   }
160
161   /**
162    * Method enumerateSequenceSet.
163    * 
164    * @return an Enumeration over all SequenceSet elements
165    */
166   public java.util.Enumeration enumerateSequenceSet()
167   {
168     return this._sequenceSetList.elements();
169   }
170
171   /**
172    * Method enumerateTree.
173    * 
174    * @return an Enumeration over all java.lang.String elements
175    */
176   public java.util.Enumeration enumerateTree()
177   {
178     return this._treeList.elements();
179   }
180
181   /**
182    * Method getAlignment.
183    * 
184    * @param index
185    * @throws java.lang.IndexOutOfBoundsException
186    *           if the index given is outside the bounds of the collection
187    * @return the value of the Alignment at the given index
188    */
189   public Alignment getAlignment(final int index)
190           throws java.lang.IndexOutOfBoundsException
191   {
192     // check bounds for index
193     if (index < 0 || index >= this._alignmentList.size())
194     {
195       throw new IndexOutOfBoundsException("getAlignment: Index value '"
196               + index + "' not in range [0.."
197               + (this._alignmentList.size() - 1) + "]");
198     }
199
200     return (Alignment) _alignmentList.get(index);
201   }
202
203   /**
204    * Method getAlignment.Returns the contents of the collection in an Array.
205    * <p>
206    * Note: Just in case the collection contents are changing in another thread,
207    * we pass a 0-length Array of the correct type into the API call. This way we
208    * <i>know</i> that the Array returned is of exactly the correct length.
209    * 
210    * @return this collection as an Array
211    */
212   public Alignment[] getAlignment()
213   {
214     Alignment[] array = new Alignment[0];
215     return (Alignment[]) this._alignmentList.toArray(array);
216   }
217
218   /**
219    * Method getAlignmentCount.
220    * 
221    * @return the size of this collection
222    */
223   public int getAlignmentCount()
224   {
225     return this._alignmentList.size();
226   }
227
228   /**
229    * Method getSequenceSet.
230    * 
231    * @param index
232    * @throws java.lang.IndexOutOfBoundsException
233    *           if the index given is outside the bounds of the collection
234    * @return the value of the SequenceSet at the given index
235    */
236   public SequenceSet getSequenceSet(final int index)
237           throws java.lang.IndexOutOfBoundsException
238   {
239     // check bounds for index
240     if (index < 0 || index >= this._sequenceSetList.size())
241     {
242       throw new IndexOutOfBoundsException("getSequenceSet: Index value '"
243               + index + "' not in range [0.."
244               + (this._sequenceSetList.size() - 1) + "]");
245     }
246
247     return (SequenceSet) _sequenceSetList.get(index);
248   }
249
250   /**
251    * Method getSequenceSet.Returns the contents of the collection in an Array.
252    * <p>
253    * Note: Just in case the collection contents are changing in another thread,
254    * we pass a 0-length Array of the correct type into the API call. This way we
255    * <i>know</i> that the Array returned is of exactly the correct length.
256    * 
257    * @return this collection as an Array
258    */
259   public SequenceSet[] getSequenceSet()
260   {
261     SequenceSet[] array = new SequenceSet[0];
262     return (SequenceSet[]) this._sequenceSetList.toArray(array);
263   }
264
265   /**
266    * Method getSequenceSetCount.
267    * 
268    * @return the size of this collection
269    */
270   public int getSequenceSetCount()
271   {
272     return this._sequenceSetList.size();
273   }
274
275   /**
276    * Method getTree.
277    * 
278    * @param index
279    * @throws java.lang.IndexOutOfBoundsException
280    *           if the index given is outside the bounds of the collection
281    * @return the value of the java.lang.String at the given index
282    */
283   public java.lang.String getTree(final int index)
284           throws java.lang.IndexOutOfBoundsException
285   {
286     // check bounds for index
287     if (index < 0 || index >= this._treeList.size())
288     {
289       throw new IndexOutOfBoundsException("getTree: Index value '" + index
290               + "' not in range [0.." + (this._treeList.size() - 1) + "]");
291     }
292
293     return (java.lang.String) _treeList.get(index);
294   }
295
296   /**
297    * Method getTree.Returns the contents of the collection in an Array.
298    * <p>
299    * Note: Just in case the collection contents are changing in another thread,
300    * we pass a 0-length Array of the correct type into the API call. This way we
301    * <i>know</i> that the Array returned is of exactly the correct length.
302    * 
303    * @return this collection as an Array
304    */
305   public java.lang.String[] getTree()
306   {
307     java.lang.String[] array = new java.lang.String[0];
308     return (java.lang.String[]) this._treeList.toArray(array);
309   }
310
311   /**
312    * Method getTreeCount.
313    * 
314    * @return the size of this collection
315    */
316   public int getTreeCount()
317   {
318     return this._treeList.size();
319   }
320
321   /**
322    * Method isValid.
323    * 
324    * @return true if this object is valid according to the schema
325    */
326   public boolean isValid()
327   {
328     try
329     {
330       validate();
331     } catch (org.exolab.castor.xml.ValidationException vex)
332     {
333       return false;
334     }
335     return true;
336   }
337
338   /**
339    * 
340    * 
341    * @param out
342    * @throws org.exolab.castor.xml.MarshalException
343    *           if object is null or if any SAXException is thrown during
344    *           marshaling
345    * @throws org.exolab.castor.xml.ValidationException
346    *           if this object is an invalid instance according to the schema
347    */
348   public void marshal(final java.io.Writer out)
349           throws org.exolab.castor.xml.MarshalException,
350           org.exolab.castor.xml.ValidationException
351   {
352     Marshaller.marshal(this, out);
353   }
354
355   /**
356    * 
357    * 
358    * @param handler
359    * @throws java.io.IOException
360    *           if an IOException occurs during marshaling
361    * @throws org.exolab.castor.xml.ValidationException
362    *           if this object is an invalid instance according to the schema
363    * @throws org.exolab.castor.xml.MarshalException
364    *           if object is null or if any SAXException is thrown during
365    *           marshaling
366    */
367   public void marshal(final org.xml.sax.ContentHandler handler)
368           throws java.io.IOException,
369           org.exolab.castor.xml.MarshalException,
370           org.exolab.castor.xml.ValidationException
371   {
372     Marshaller.marshal(this, handler);
373   }
374
375   /**
376    * Method removeAlignment.
377    * 
378    * @param vAlignment
379    * @return true if the object was removed from the collection.
380    */
381   public boolean removeAlignment(final Alignment vAlignment)
382   {
383     boolean removed = _alignmentList.remove(vAlignment);
384     return removed;
385   }
386
387   /**
388    * Method removeAlignmentAt.
389    * 
390    * @param index
391    * @return the element removed from the collection
392    */
393   public Alignment removeAlignmentAt(final int index)
394   {
395     java.lang.Object obj = this._alignmentList.remove(index);
396     return (Alignment) obj;
397   }
398
399   /**
400      */
401   public void removeAllAlignment()
402   {
403     this._alignmentList.clear();
404   }
405
406   /**
407      */
408   public void removeAllSequenceSet()
409   {
410     this._sequenceSetList.clear();
411   }
412
413   /**
414      */
415   public void removeAllTree()
416   {
417     this._treeList.clear();
418   }
419
420   /**
421    * Method removeSequenceSet.
422    * 
423    * @param vSequenceSet
424    * @return true if the object was removed from the collection.
425    */
426   public boolean removeSequenceSet(final SequenceSet vSequenceSet)
427   {
428     boolean removed = _sequenceSetList.remove(vSequenceSet);
429     return removed;
430   }
431
432   /**
433    * Method removeSequenceSetAt.
434    * 
435    * @param index
436    * @return the element removed from the collection
437    */
438   public SequenceSet removeSequenceSetAt(final int index)
439   {
440     java.lang.Object obj = this._sequenceSetList.remove(index);
441     return (SequenceSet) obj;
442   }
443
444   /**
445    * Method removeTree.
446    * 
447    * @param vTree
448    * @return true if the object was removed from the collection.
449    */
450   public boolean removeTree(final java.lang.String vTree)
451   {
452     boolean removed = _treeList.remove(vTree);
453     return removed;
454   }
455
456   /**
457    * Method removeTreeAt.
458    * 
459    * @param index
460    * @return the element removed from the collection
461    */
462   public java.lang.String removeTreeAt(final int index)
463   {
464     java.lang.Object obj = this._treeList.remove(index);
465     return (java.lang.String) obj;
466   }
467
468   /**
469    * 
470    * 
471    * @param index
472    * @param vAlignment
473    * @throws java.lang.IndexOutOfBoundsException
474    *           if the index given is outside the bounds of the collection
475    */
476   public void setAlignment(final int index, final Alignment vAlignment)
477           throws java.lang.IndexOutOfBoundsException
478   {
479     // check bounds for index
480     if (index < 0 || index >= this._alignmentList.size())
481     {
482       throw new IndexOutOfBoundsException("setAlignment: Index value '"
483               + index + "' not in range [0.."
484               + (this._alignmentList.size() - 1) + "]");
485     }
486
487     this._alignmentList.set(index, vAlignment);
488   }
489
490   /**
491    * 
492    * 
493    * @param vAlignmentArray
494    */
495   public void setAlignment(final Alignment[] vAlignmentArray)
496   {
497     // -- copy array
498     _alignmentList.clear();
499
500     for (int i = 0; i < vAlignmentArray.length; i++)
501     {
502       this._alignmentList.add(vAlignmentArray[i]);
503     }
504   }
505
506   /**
507    * 
508    * 
509    * @param index
510    * @param vSequenceSet
511    * @throws java.lang.IndexOutOfBoundsException
512    *           if the index given is outside the bounds of the collection
513    */
514   public void setSequenceSet(final int index, final SequenceSet vSequenceSet)
515           throws java.lang.IndexOutOfBoundsException
516   {
517     // check bounds for index
518     if (index < 0 || index >= this._sequenceSetList.size())
519     {
520       throw new IndexOutOfBoundsException("setSequenceSet: Index value '"
521               + index + "' not in range [0.."
522               + (this._sequenceSetList.size() - 1) + "]");
523     }
524
525     this._sequenceSetList.set(index, vSequenceSet);
526   }
527
528   /**
529    * 
530    * 
531    * @param vSequenceSetArray
532    */
533   public void setSequenceSet(final SequenceSet[] vSequenceSetArray)
534   {
535     // -- copy array
536     _sequenceSetList.clear();
537
538     for (int i = 0; i < vSequenceSetArray.length; i++)
539     {
540       this._sequenceSetList.add(vSequenceSetArray[i]);
541     }
542   }
543
544   /**
545    * 
546    * 
547    * @param index
548    * @param vTree
549    * @throws java.lang.IndexOutOfBoundsException
550    *           if the index given is outside the bounds of the collection
551    */
552   public void setTree(final int index, final java.lang.String vTree)
553           throws java.lang.IndexOutOfBoundsException
554   {
555     // check bounds for index
556     if (index < 0 || index >= this._treeList.size())
557     {
558       throw new IndexOutOfBoundsException("setTree: Index value '" + index
559               + "' not in range [0.." + (this._treeList.size() - 1) + "]");
560     }
561
562     this._treeList.set(index, vTree);
563   }
564
565   /**
566    * 
567    * 
568    * @param vTreeArray
569    */
570   public void setTree(final java.lang.String[] vTreeArray)
571   {
572     // -- copy array
573     _treeList.clear();
574
575     for (int i = 0; i < vTreeArray.length; i++)
576     {
577       this._treeList.add(vTreeArray[i]);
578     }
579   }
580
581   /**
582    * Method unmarshal.
583    * 
584    * @param reader
585    * @throws org.exolab.castor.xml.MarshalException
586    *           if object is null or if any SAXException is thrown during
587    *           marshaling
588    * @throws org.exolab.castor.xml.ValidationException
589    *           if this object is an invalid instance according to the schema
590    * @return the unmarshaled jalview.binding.VAMSAS
591    */
592   public static jalview.binding.VAMSAS unmarshal(final java.io.Reader reader)
593           throws org.exolab.castor.xml.MarshalException,
594           org.exolab.castor.xml.ValidationException
595   {
596     return (jalview.binding.VAMSAS) Unmarshaller.unmarshal(
597             jalview.binding.VAMSAS.class, reader);
598   }
599
600   /**
601    * 
602    * 
603    * @throws org.exolab.castor.xml.ValidationException
604    *           if this object is an invalid instance according to the schema
605    */
606   public void validate() throws org.exolab.castor.xml.ValidationException
607   {
608     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
609     validator.validate(this);
610   }
611
612 }