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