2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
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;
72 this._sequenceList = new java.util.Vector();
73 this._annotationList = new java.util.Vector();
84 * @throws java.lang.IndexOutOfBoundsException
85 * if the index given is outside the bounds of the collection
87 public void addAnnotation(final jalview.binding.Annotation vAnnotation)
88 throws java.lang.IndexOutOfBoundsException
90 this._annotationList.addElement(vAnnotation);
98 * @throws java.lang.IndexOutOfBoundsException
99 * if the index given is outside the bounds of the collection
101 public void addAnnotation(final int index,
102 final jalview.binding.Annotation vAnnotation)
103 throws java.lang.IndexOutOfBoundsException
105 this._annotationList.add(index, vAnnotation);
112 * @throws java.lang.IndexOutOfBoundsException
113 * if the index given is outside the bounds of the collection
115 public void addSequence(final jalview.binding.Sequence vSequence)
116 throws java.lang.IndexOutOfBoundsException
118 this._sequenceList.addElement(vSequence);
126 * @throws java.lang.IndexOutOfBoundsException
127 * if the index given is outside the bounds of the collection
129 public void addSequence(final int index,
130 final jalview.binding.Sequence vSequence)
131 throws java.lang.IndexOutOfBoundsException
133 this._sequenceList.add(index, vSequence);
138 public void deleteAligned()
140 this._has_aligned = false;
144 * Method enumerateAnnotation.
146 * @return an Enumeration over all jalview.binding.Annotation elements
148 public java.util.Enumeration enumerateAnnotation()
150 return this._annotationList.elements();
154 * Method enumerateSequence.
156 * @return an Enumeration over all jalview.binding.Sequence elements
158 public java.util.Enumeration enumerateSequence()
160 return this._sequenceList.elements();
164 * Returns the value of field 'aligned'.
166 * @return the value of field 'Aligned'.
168 public boolean getAligned()
170 return this._aligned;
174 * Method getAnnotation.
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
181 public jalview.binding.Annotation getAnnotation(final int index)
182 throws java.lang.IndexOutOfBoundsException
184 // check bounds for index
185 if (index < 0 || index >= this._annotationList.size())
187 throw new IndexOutOfBoundsException("getAnnotation: Index value '"
188 + index + "' not in range [0.."
189 + (this._annotationList.size() - 1) + "]");
192 return (jalview.binding.Annotation) _annotationList.get(index);
196 * Method getAnnotation.Returns the contents of the collection in an Array.
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.
202 * @return this collection as an Array
204 public jalview.binding.Annotation[] getAnnotation()
206 jalview.binding.Annotation[] array = new jalview.binding.Annotation[0];
207 return (jalview.binding.Annotation[]) this._annotationList
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
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
239 public jalview.binding.Sequence getSequence(final int index)
240 throws java.lang.IndexOutOfBoundsException
242 // check bounds for index
243 if (index < 0 || index >= this._sequenceList.size())
245 throw new IndexOutOfBoundsException("getSequence: Index value '"
246 + index + "' not in range [0.."
247 + (this._sequenceList.size() - 1) + "]");
250 return (jalview.binding.Sequence) _sequenceList.get(index);
254 * Method getSequence.Returns the contents of the collection in an Array.
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.
260 * @return this collection as an Array
262 public jalview.binding.Sequence[] getSequence()
264 jalview.binding.Sequence[] array = new jalview.binding.Sequence[0];
265 return (jalview.binding.Sequence[]) this._sequenceList.toArray(array);
269 * Method getSequenceCount.
271 * @return the size of this collection
273 public int getSequenceCount()
275 return this._sequenceList.size();
281 * @return true if at least one Aligned has been added
283 public boolean hasAligned()
285 return this._has_aligned;
289 * Returns the value of field 'aligned'.
291 * @return the value of field 'Aligned'.
293 public boolean isAligned()
295 return this._aligned;
301 * @return true if this object is valid according to the schema
303 public boolean isValid()
308 } catch (org.exolab.castor.xml.ValidationException vex)
319 * @throws org.exolab.castor.xml.MarshalException
320 * if object is null or if any SAXException is thrown during
322 * @throws org.exolab.castor.xml.ValidationException
323 * if this object is an invalid instance according to the schema
325 public void marshal(final java.io.Writer out)
326 throws org.exolab.castor.xml.MarshalException,
327 org.exolab.castor.xml.ValidationException
329 Marshaller.marshal(this, out);
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
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
349 Marshaller.marshal(this, handler);
354 public void removeAllAnnotation()
356 this._annotationList.clear();
361 public void removeAllSequence()
363 this._sequenceList.clear();
367 * Method removeAnnotation.
370 * @return true if the object was removed from the collection.
372 public boolean removeAnnotation(
373 final jalview.binding.Annotation vAnnotation)
375 boolean removed = _annotationList.remove(vAnnotation);
380 * Method removeAnnotationAt.
383 * @return the element removed from the collection
385 public jalview.binding.Annotation removeAnnotationAt(final int index)
387 java.lang.Object obj = this._annotationList.remove(index);
388 return (jalview.binding.Annotation) obj;
392 * Method removeSequence.
395 * @return true if the object was removed from the collection.
397 public boolean removeSequence(final jalview.binding.Sequence vSequence)
399 boolean removed = _sequenceList.remove(vSequence);
404 * Method removeSequenceAt.
407 * @return the element removed from the collection
409 public jalview.binding.Sequence removeSequenceAt(final int index)
411 java.lang.Object obj = this._sequenceList.remove(index);
412 return (jalview.binding.Sequence) obj;
416 * Sets the value of field 'aligned'.
419 * the value of field 'aligned'.
421 public void setAligned(final boolean aligned)
423 this._aligned = aligned;
424 this._has_aligned = true;
432 * @throws java.lang.IndexOutOfBoundsException
433 * if the index given is outside the bounds of the collection
435 public void setAnnotation(final int index,
436 final jalview.binding.Annotation vAnnotation)
437 throws java.lang.IndexOutOfBoundsException
439 // check bounds for index
440 if (index < 0 || index >= this._annotationList.size())
442 throw new IndexOutOfBoundsException("setAnnotation: Index value '"
443 + index + "' not in range [0.."
444 + (this._annotationList.size() - 1) + "]");
447 this._annotationList.set(index, vAnnotation);
453 * @param vAnnotationArray
455 public void setAnnotation(
456 final jalview.binding.Annotation[] vAnnotationArray)
459 _annotationList.clear();
461 for (int i = 0; i < vAnnotationArray.length; i++)
463 this._annotationList.add(vAnnotationArray[i]);
468 * Sets the value of field 'gapChar'.
471 * the value of field 'gapChar'.
473 public void setGapChar(final java.lang.String gapChar)
475 this._gapChar = gapChar;
483 * @throws java.lang.IndexOutOfBoundsException
484 * if the index given is outside the bounds of the collection
486 public void setSequence(final int index,
487 final jalview.binding.Sequence vSequence)
488 throws java.lang.IndexOutOfBoundsException
490 // check bounds for index
491 if (index < 0 || index >= this._sequenceList.size())
493 throw new IndexOutOfBoundsException("setSequence: Index value '"
494 + index + "' not in range [0.."
495 + (this._sequenceList.size() - 1) + "]");
498 this._sequenceList.set(index, vSequence);
504 * @param vSequenceArray
506 public void setSequence(final jalview.binding.Sequence[] vSequenceArray)
509 _sequenceList.clear();
511 for (int i = 0; i < vSequenceArray.length; i++)
513 this._sequenceList.add(vSequenceArray[i]);
521 * @throws org.exolab.castor.xml.MarshalException
522 * if object is null or if any SAXException is thrown during
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
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
533 return (jalview.binding.SequenceSet) Unmarshaller.unmarshal(
534 jalview.binding.SequenceSet.class, reader);
540 * @throws org.exolab.castor.xml.ValidationException
541 * if this object is an invalid instance according to the schema
543 public void validate() throws org.exolab.castor.xml.ValidationException
545 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
546 validator.validate(this);