JAL-1432 updated copyright notices
[jalview.git] / src / jalview / binding / SequenceSet.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3  * Copyright (C) 2014 The Jalview Authors
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  * The Jalview Authors are detailed in the 'AUTHORS' file.
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 SequenceSet.
30  * 
31  * @version $Revision$ $Date$
32  */
33 public class SequenceSet implements java.io.Serializable
34 {
35
36   // --------------------------/
37   // - Class/Member Variables -/
38   // --------------------------/
39
40   /**
41    * Field _gapChar.
42    */
43   private java.lang.String _gapChar;
44
45   /**
46    * Field _aligned.
47    */
48   private boolean _aligned;
49
50   /**
51    * keeps track of state for field: _aligned
52    */
53   private boolean _has_aligned;
54
55   /**
56    * Field _sequenceList.
57    */
58   private java.util.Vector _sequenceList;
59
60   /**
61    * Field _annotationList.
62    */
63   private java.util.Vector _annotationList;
64
65   // ----------------/
66   // - Constructors -/
67   // ----------------/
68
69   public SequenceSet()
70   {
71     super();
72     this._sequenceList = new java.util.Vector();
73     this._annotationList = new java.util.Vector();
74   }
75
76   // -----------/
77   // - Methods -/
78   // -----------/
79
80   /**
81    * 
82    * 
83    * @param vAnnotation
84    * @throws java.lang.IndexOutOfBoundsException
85    *           if the index given is outside the bounds of the collection
86    */
87   public void addAnnotation(final jalview.binding.Annotation vAnnotation)
88           throws java.lang.IndexOutOfBoundsException
89   {
90     this._annotationList.addElement(vAnnotation);
91   }
92
93   /**
94    * 
95    * 
96    * @param index
97    * @param vAnnotation
98    * @throws java.lang.IndexOutOfBoundsException
99    *           if the index given is outside the bounds of the collection
100    */
101   public void addAnnotation(final int index,
102           final jalview.binding.Annotation vAnnotation)
103           throws java.lang.IndexOutOfBoundsException
104   {
105     this._annotationList.add(index, vAnnotation);
106   }
107
108   /**
109    * 
110    * 
111    * @param vSequence
112    * @throws java.lang.IndexOutOfBoundsException
113    *           if the index given is outside the bounds of the collection
114    */
115   public void addSequence(final jalview.binding.Sequence vSequence)
116           throws java.lang.IndexOutOfBoundsException
117   {
118     this._sequenceList.addElement(vSequence);
119   }
120
121   /**
122    * 
123    * 
124    * @param index
125    * @param vSequence
126    * @throws java.lang.IndexOutOfBoundsException
127    *           if the index given is outside the bounds of the collection
128    */
129   public void addSequence(final int index,
130           final jalview.binding.Sequence vSequence)
131           throws java.lang.IndexOutOfBoundsException
132   {
133     this._sequenceList.add(index, vSequence);
134   }
135
136   /**
137      */
138   public void deleteAligned()
139   {
140     this._has_aligned = false;
141   }
142
143   /**
144    * Method enumerateAnnotation.
145    * 
146    * @return an Enumeration over all jalview.binding.Annotation elements
147    */
148   public java.util.Enumeration enumerateAnnotation()
149   {
150     return this._annotationList.elements();
151   }
152
153   /**
154    * Method enumerateSequence.
155    * 
156    * @return an Enumeration over all jalview.binding.Sequence elements
157    */
158   public java.util.Enumeration enumerateSequence()
159   {
160     return this._sequenceList.elements();
161   }
162
163   /**
164    * Returns the value of field 'aligned'.
165    * 
166    * @return the value of field 'Aligned'.
167    */
168   public boolean getAligned()
169   {
170     return this._aligned;
171   }
172
173   /**
174    * Method getAnnotation.
175    * 
176    * @param index
177    * @throws java.lang.IndexOutOfBoundsException
178    *           if the index given is outside the bounds of the collection
179    * @return the value of the jalview.binding.Annotation at the given index
180    */
181   public jalview.binding.Annotation getAnnotation(final int index)
182           throws java.lang.IndexOutOfBoundsException
183   {
184     // check bounds for index
185     if (index < 0 || index >= this._annotationList.size())
186     {
187       throw new IndexOutOfBoundsException("getAnnotation: Index value '"
188               + index + "' not in range [0.."
189               + (this._annotationList.size() - 1) + "]");
190     }
191
192     return (jalview.binding.Annotation) _annotationList.get(index);
193   }
194
195   /**
196    * Method getAnnotation.Returns the contents of the collection in an Array.
197    * <p>
198    * Note: Just in case the collection contents are changing in another thread,
199    * we pass a 0-length Array of the correct type into the API call. This way we
200    * <i>know</i> that the Array returned is of exactly the correct length.
201    * 
202    * @return this collection as an Array
203    */
204   public jalview.binding.Annotation[] getAnnotation()
205   {
206     jalview.binding.Annotation[] array = new jalview.binding.Annotation[0];
207     return (jalview.binding.Annotation[]) this._annotationList
208             .toArray(array);
209   }
210
211   /**
212    * Method getAnnotationCount.
213    * 
214    * @return the size of this collection
215    */
216   public int getAnnotationCount()
217   {
218     return this._annotationList.size();
219   }
220
221   /**
222    * Returns the value of field 'gapChar'.
223    * 
224    * @return the value of field 'GapChar'.
225    */
226   public java.lang.String getGapChar()
227   {
228     return this._gapChar;
229   }
230
231   /**
232    * Method getSequence.
233    * 
234    * @param index
235    * @throws java.lang.IndexOutOfBoundsException
236    *           if the index given is outside the bounds of the collection
237    * @return the value of the jalview.binding.Sequence at the given index
238    */
239   public jalview.binding.Sequence getSequence(final int index)
240           throws java.lang.IndexOutOfBoundsException
241   {
242     // check bounds for index
243     if (index < 0 || index >= this._sequenceList.size())
244     {
245       throw new IndexOutOfBoundsException("getSequence: Index value '"
246               + index + "' not in range [0.."
247               + (this._sequenceList.size() - 1) + "]");
248     }
249
250     return (jalview.binding.Sequence) _sequenceList.get(index);
251   }
252
253   /**
254    * Method getSequence.Returns the contents of the collection in an Array.
255    * <p>
256    * Note: Just in case the collection contents are changing in another thread,
257    * we pass a 0-length Array of the correct type into the API call. This way we
258    * <i>know</i> that the Array returned is of exactly the correct length.
259    * 
260    * @return this collection as an Array
261    */
262   public jalview.binding.Sequence[] getSequence()
263   {
264     jalview.binding.Sequence[] array = new jalview.binding.Sequence[0];
265     return (jalview.binding.Sequence[]) this._sequenceList.toArray(array);
266   }
267
268   /**
269    * Method getSequenceCount.
270    * 
271    * @return the size of this collection
272    */
273   public int getSequenceCount()
274   {
275     return this._sequenceList.size();
276   }
277
278   /**
279    * Method hasAligned.
280    * 
281    * @return true if at least one Aligned has been added
282    */
283   public boolean hasAligned()
284   {
285     return this._has_aligned;
286   }
287
288   /**
289    * Returns the value of field 'aligned'.
290    * 
291    * @return the value of field 'Aligned'.
292    */
293   public boolean isAligned()
294   {
295     return this._aligned;
296   }
297
298   /**
299    * Method isValid.
300    * 
301    * @return true if this object is valid according to the schema
302    */
303   public boolean isValid()
304   {
305     try
306     {
307       validate();
308     } catch (org.exolab.castor.xml.ValidationException vex)
309     {
310       return false;
311     }
312     return true;
313   }
314
315   /**
316    * 
317    * 
318    * @param out
319    * @throws org.exolab.castor.xml.MarshalException
320    *           if object is null or if any SAXException is thrown during
321    *           marshaling
322    * @throws org.exolab.castor.xml.ValidationException
323    *           if this object is an invalid instance according to the schema
324    */
325   public void marshal(final java.io.Writer out)
326           throws org.exolab.castor.xml.MarshalException,
327           org.exolab.castor.xml.ValidationException
328   {
329     Marshaller.marshal(this, out);
330   }
331
332   /**
333    * 
334    * 
335    * @param handler
336    * @throws java.io.IOException
337    *           if an IOException occurs during marshaling
338    * @throws org.exolab.castor.xml.ValidationException
339    *           if this object is an invalid instance according to the schema
340    * @throws org.exolab.castor.xml.MarshalException
341    *           if object is null or if any SAXException is thrown during
342    *           marshaling
343    */
344   public void marshal(final org.xml.sax.ContentHandler handler)
345           throws java.io.IOException,
346           org.exolab.castor.xml.MarshalException,
347           org.exolab.castor.xml.ValidationException
348   {
349     Marshaller.marshal(this, handler);
350   }
351
352   /**
353      */
354   public void removeAllAnnotation()
355   {
356     this._annotationList.clear();
357   }
358
359   /**
360      */
361   public void removeAllSequence()
362   {
363     this._sequenceList.clear();
364   }
365
366   /**
367    * Method removeAnnotation.
368    * 
369    * @param vAnnotation
370    * @return true if the object was removed from the collection.
371    */
372   public boolean removeAnnotation(
373           final jalview.binding.Annotation vAnnotation)
374   {
375     boolean removed = _annotationList.remove(vAnnotation);
376     return removed;
377   }
378
379   /**
380    * Method removeAnnotationAt.
381    * 
382    * @param index
383    * @return the element removed from the collection
384    */
385   public jalview.binding.Annotation removeAnnotationAt(final int index)
386   {
387     java.lang.Object obj = this._annotationList.remove(index);
388     return (jalview.binding.Annotation) obj;
389   }
390
391   /**
392    * Method removeSequence.
393    * 
394    * @param vSequence
395    * @return true if the object was removed from the collection.
396    */
397   public boolean removeSequence(final jalview.binding.Sequence vSequence)
398   {
399     boolean removed = _sequenceList.remove(vSequence);
400     return removed;
401   }
402
403   /**
404    * Method removeSequenceAt.
405    * 
406    * @param index
407    * @return the element removed from the collection
408    */
409   public jalview.binding.Sequence removeSequenceAt(final int index)
410   {
411     java.lang.Object obj = this._sequenceList.remove(index);
412     return (jalview.binding.Sequence) obj;
413   }
414
415   /**
416    * Sets the value of field 'aligned'.
417    * 
418    * @param aligned
419    *          the value of field 'aligned'.
420    */
421   public void setAligned(final boolean aligned)
422   {
423     this._aligned = aligned;
424     this._has_aligned = true;
425   }
426
427   /**
428    * 
429    * 
430    * @param index
431    * @param vAnnotation
432    * @throws java.lang.IndexOutOfBoundsException
433    *           if the index given is outside the bounds of the collection
434    */
435   public void setAnnotation(final int index,
436           final jalview.binding.Annotation vAnnotation)
437           throws java.lang.IndexOutOfBoundsException
438   {
439     // check bounds for index
440     if (index < 0 || index >= this._annotationList.size())
441     {
442       throw new IndexOutOfBoundsException("setAnnotation: Index value '"
443               + index + "' not in range [0.."
444               + (this._annotationList.size() - 1) + "]");
445     }
446
447     this._annotationList.set(index, vAnnotation);
448   }
449
450   /**
451    * 
452    * 
453    * @param vAnnotationArray
454    */
455   public void setAnnotation(
456           final jalview.binding.Annotation[] vAnnotationArray)
457   {
458     // -- copy array
459     _annotationList.clear();
460
461     for (int i = 0; i < vAnnotationArray.length; i++)
462     {
463       this._annotationList.add(vAnnotationArray[i]);
464     }
465   }
466
467   /**
468    * Sets the value of field 'gapChar'.
469    * 
470    * @param gapChar
471    *          the value of field 'gapChar'.
472    */
473   public void setGapChar(final java.lang.String gapChar)
474   {
475     this._gapChar = gapChar;
476   }
477
478   /**
479    * 
480    * 
481    * @param index
482    * @param vSequence
483    * @throws java.lang.IndexOutOfBoundsException
484    *           if the index given is outside the bounds of the collection
485    */
486   public void setSequence(final int index,
487           final jalview.binding.Sequence vSequence)
488           throws java.lang.IndexOutOfBoundsException
489   {
490     // check bounds for index
491     if (index < 0 || index >= this._sequenceList.size())
492     {
493       throw new IndexOutOfBoundsException("setSequence: Index value '"
494               + index + "' not in range [0.."
495               + (this._sequenceList.size() - 1) + "]");
496     }
497
498     this._sequenceList.set(index, vSequence);
499   }
500
501   /**
502    * 
503    * 
504    * @param vSequenceArray
505    */
506   public void setSequence(final jalview.binding.Sequence[] vSequenceArray)
507   {
508     // -- copy array
509     _sequenceList.clear();
510
511     for (int i = 0; i < vSequenceArray.length; i++)
512     {
513       this._sequenceList.add(vSequenceArray[i]);
514     }
515   }
516
517   /**
518    * Method unmarshal.
519    * 
520    * @param reader
521    * @throws org.exolab.castor.xml.MarshalException
522    *           if object is null or if any SAXException is thrown during
523    *           marshaling
524    * @throws org.exolab.castor.xml.ValidationException
525    *           if this object is an invalid instance according to the schema
526    * @return the unmarshaled jalview.binding.SequenceSet
527    */
528   public static jalview.binding.SequenceSet unmarshal(
529           final java.io.Reader reader)
530           throws org.exolab.castor.xml.MarshalException,
531           org.exolab.castor.xml.ValidationException
532   {
533     return (jalview.binding.SequenceSet) Unmarshaller.unmarshal(
534             jalview.binding.SequenceSet.class, reader);
535   }
536
537   /**
538    * 
539    * 
540    * @throws org.exolab.castor.xml.ValidationException
541    *           if this object is an invalid instance according to the schema
542    */
543   public void validate() throws org.exolab.castor.xml.ValidationException
544   {
545     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
546     validator.validate(this);
547   }
548
549 }