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