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