2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
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.
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.
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
19 package jalview.binding;
21 //---------------------------------/
22 //- Imported classes and packages -/
23 //---------------------------------/
25 import org.exolab.castor.xml.Marshaller;
26 import org.exolab.castor.xml.Unmarshaller;
31 * @version $Revision$ $Date$
33 public class SequenceSet implements java.io.Serializable {
36 //--------------------------/
37 //- Class/Member Variables -/
38 //--------------------------/
43 private java.lang.String _gapChar;
48 private boolean _aligned;
51 * keeps track of state for field: _aligned
53 private boolean _has_aligned;
56 * Field _sequenceList.
58 private java.util.Vector _sequenceList;
61 * Field _annotationList.
63 private java.util.Vector _annotationList;
70 public SequenceSet() {
72 this._sequenceList = new java.util.Vector();
73 this._annotationList = new java.util.Vector();
85 * @throws java.lang.IndexOutOfBoundsException if the index
86 * given is outside the bounds of the collection
88 public void addAnnotation(
89 final jalview.binding.Annotation vAnnotation)
90 throws java.lang.IndexOutOfBoundsException {
91 this._annotationList.addElement(vAnnotation);
99 * @throws java.lang.IndexOutOfBoundsException if the index
100 * given is outside the bounds of the collection
102 public void addAnnotation(
104 final jalview.binding.Annotation vAnnotation)
105 throws java.lang.IndexOutOfBoundsException {
106 this._annotationList.add(index, vAnnotation);
113 * @throws java.lang.IndexOutOfBoundsException if the index
114 * given is outside the bounds of the collection
116 public void addSequence(
117 final jalview.binding.Sequence vSequence)
118 throws java.lang.IndexOutOfBoundsException {
119 this._sequenceList.addElement(vSequence);
127 * @throws java.lang.IndexOutOfBoundsException if the index
128 * given is outside the bounds of the collection
130 public void addSequence(
132 final jalview.binding.Sequence vSequence)
133 throws java.lang.IndexOutOfBoundsException {
134 this._sequenceList.add(index, vSequence);
139 public void deleteAligned(
141 this._has_aligned= false;
145 * Method enumerateAnnotation.
147 * @return an Enumeration over all jalview.binding.Annotation
150 public java.util.Enumeration enumerateAnnotation(
152 return this._annotationList.elements();
156 * Method enumerateSequence.
158 * @return an Enumeration over all jalview.binding.Sequence
161 public java.util.Enumeration enumerateSequence(
163 return this._sequenceList.elements();
167 * Returns the value of field 'aligned'.
169 * @return the value of field 'Aligned'.
171 public boolean getAligned(
173 return this._aligned;
177 * Method getAnnotation.
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
185 public jalview.binding.Annotation getAnnotation(
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) + "]");
193 return (jalview.binding.Annotation) _annotationList.get(index);
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.
203 * @return this collection as an Array
205 public jalview.binding.Annotation[] getAnnotation(
207 jalview.binding.Annotation[] array = new jalview.binding.Annotation[0];
208 return (jalview.binding.Annotation[]) this._annotationList.toArray(array);
212 * Method getAnnotationCount.
214 * @return the size of this collection
216 public int getAnnotationCount(
218 return this._annotationList.size();
222 * Returns the value of field 'gapChar'.
224 * @return the value of field 'GapChar'.
226 public java.lang.String getGapChar(
228 return this._gapChar;
232 * Method getSequence.
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
240 public jalview.binding.Sequence getSequence(
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) + "]");
248 return (jalview.binding.Sequence) _sequenceList.get(index);
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.
258 * @return this collection as an Array
260 public jalview.binding.Sequence[] getSequence(
262 jalview.binding.Sequence[] array = new jalview.binding.Sequence[0];
263 return (jalview.binding.Sequence[]) this._sequenceList.toArray(array);
267 * Method getSequenceCount.
269 * @return the size of this collection
271 public int getSequenceCount(
273 return this._sequenceList.size();
279 * @return true if at least one Aligned has been added
281 public boolean hasAligned(
283 return this._has_aligned;
287 * Returns the value of field 'aligned'.
289 * @return the value of field 'Aligned'.
291 public boolean isAligned(
293 return this._aligned;
299 * @return true if this object is valid according to the schema
301 public boolean isValid(
305 } catch (org.exolab.castor.xml.ValidationException vex) {
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
321 final java.io.Writer out)
322 throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
323 Marshaller.marshal(this, out);
330 * @throws java.io.IOException if an IOException occurs during
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
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);
345 public void removeAllAnnotation(
347 this._annotationList.clear();
352 public void removeAllSequence(
354 this._sequenceList.clear();
358 * Method removeAnnotation.
361 * @return true if the object was removed from the collection.
363 public boolean removeAnnotation(
364 final jalview.binding.Annotation vAnnotation) {
365 boolean removed = _annotationList.remove(vAnnotation);
370 * Method removeAnnotationAt.
373 * @return the element removed from the collection
375 public jalview.binding.Annotation removeAnnotationAt(
377 java.lang.Object obj = this._annotationList.remove(index);
378 return (jalview.binding.Annotation) obj;
382 * Method removeSequence.
385 * @return true if the object was removed from the collection.
387 public boolean removeSequence(
388 final jalview.binding.Sequence vSequence) {
389 boolean removed = _sequenceList.remove(vSequence);
394 * Method removeSequenceAt.
397 * @return the element removed from the collection
399 public jalview.binding.Sequence removeSequenceAt(
401 java.lang.Object obj = this._sequenceList.remove(index);
402 return (jalview.binding.Sequence) obj;
406 * Sets the value of field 'aligned'.
408 * @param aligned the value of field 'aligned'.
410 public void setAligned(
411 final boolean aligned) {
412 this._aligned = aligned;
413 this._has_aligned = true;
421 * @throws java.lang.IndexOutOfBoundsException if the index
422 * given is outside the bounds of the collection
424 public void setAnnotation(
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) + "]");
433 this._annotationList.set(index, vAnnotation);
439 * @param vAnnotationArray
441 public void setAnnotation(
442 final jalview.binding.Annotation[] vAnnotationArray) {
444 _annotationList.clear();
446 for (int i = 0; i < vAnnotationArray.length; i++) {
447 this._annotationList.add(vAnnotationArray[i]);
452 * Sets the value of field 'gapChar'.
454 * @param gapChar the value of field 'gapChar'.
456 public void setGapChar(
457 final java.lang.String gapChar) {
458 this._gapChar = gapChar;
466 * @throws java.lang.IndexOutOfBoundsException if the index
467 * given is outside the bounds of the collection
469 public void setSequence(
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) + "]");
478 this._sequenceList.set(index, vSequence);
484 * @param vSequenceArray
486 public void setSequence(
487 final jalview.binding.Sequence[] vSequenceArray) {
489 _sequenceList.clear();
491 for (int i = 0; i < vSequenceArray.length; i++) {
492 this._sequenceList.add(vSequenceArray[i]);
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
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);
515 * @throws org.exolab.castor.xml.ValidationException if this
516 * object is an invalid instance according to the schema
518 public void validate(
520 throws org.exolab.castor.xml.ValidationException {
521 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
522 validator.validate(this);