2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
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
10 * of the License, or (at your option) any later version.
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.
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.
21 package jalview.binding;
23 //---------------------------------/
24 //- Imported classes and packages -/
25 //---------------------------------/
27 import org.exolab.castor.xml.Marshaller;
28 import org.exolab.castor.xml.Unmarshaller;
33 * @version $Revision$ $Date$
35 public class SequenceSet implements java.io.Serializable
38 // --------------------------/
39 // - Class/Member Variables -/
40 // --------------------------/
45 private java.lang.String _gapChar;
50 private boolean _aligned;
53 * keeps track of state for field: _aligned
55 private boolean _has_aligned;
58 * Field _sequenceList.
60 private java.util.Vector _sequenceList;
63 * Field _annotationList.
65 private java.util.Vector _annotationList;
74 this._sequenceList = new java.util.Vector();
75 this._annotationList = new java.util.Vector();
86 * @throws java.lang.IndexOutOfBoundsException
87 * if the index given is outside the bounds of the collection
89 public void addAnnotation(final jalview.binding.Annotation vAnnotation)
90 throws java.lang.IndexOutOfBoundsException
92 this._annotationList.addElement(vAnnotation);
100 * @throws java.lang.IndexOutOfBoundsException
101 * if the index given is outside the bounds of the collection
103 public void addAnnotation(final int index,
104 final jalview.binding.Annotation vAnnotation)
105 throws java.lang.IndexOutOfBoundsException
107 this._annotationList.add(index, vAnnotation);
114 * @throws java.lang.IndexOutOfBoundsException
115 * if the index given is outside the bounds of the collection
117 public void addSequence(final jalview.binding.Sequence vSequence)
118 throws java.lang.IndexOutOfBoundsException
120 this._sequenceList.addElement(vSequence);
128 * @throws java.lang.IndexOutOfBoundsException
129 * if the index given is outside the bounds of the collection
131 public void addSequence(final int index,
132 final jalview.binding.Sequence vSequence)
133 throws java.lang.IndexOutOfBoundsException
135 this._sequenceList.add(index, vSequence);
140 public void deleteAligned()
142 this._has_aligned = false;
146 * Method enumerateAnnotation.
148 * @return an Enumeration over all jalview.binding.Annotation elements
150 public java.util.Enumeration enumerateAnnotation()
152 return this._annotationList.elements();
156 * Method enumerateSequence.
158 * @return an Enumeration over all jalview.binding.Sequence elements
160 public java.util.Enumeration enumerateSequence()
162 return this._sequenceList.elements();
166 * Returns the value of field 'aligned'.
168 * @return the value of field 'Aligned'.
170 public boolean getAligned()
172 return this._aligned;
176 * Method getAnnotation.
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
183 public jalview.binding.Annotation getAnnotation(final int index)
184 throws java.lang.IndexOutOfBoundsException
186 // check bounds for index
187 if (index < 0 || index >= this._annotationList.size())
189 throw new IndexOutOfBoundsException("getAnnotation: Index value '"
190 + index + "' not in range [0.."
191 + (this._annotationList.size() - 1) + "]");
194 return (jalview.binding.Annotation) _annotationList.get(index);
198 * Method getAnnotation.Returns the contents of the collection in an Array.
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.
204 * @return this collection as an Array
206 public jalview.binding.Annotation[] getAnnotation()
208 jalview.binding.Annotation[] array = new jalview.binding.Annotation[0];
209 return (jalview.binding.Annotation[]) this._annotationList
214 * Method getAnnotationCount.
216 * @return the size of this collection
218 public int getAnnotationCount()
220 return this._annotationList.size();
224 * Returns the value of field 'gapChar'.
226 * @return the value of field 'GapChar'.
228 public java.lang.String getGapChar()
230 return this._gapChar;
234 * Method getSequence.
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
241 public jalview.binding.Sequence getSequence(final int index)
242 throws java.lang.IndexOutOfBoundsException
244 // check bounds for index
245 if (index < 0 || index >= this._sequenceList.size())
247 throw new IndexOutOfBoundsException("getSequence: Index value '"
248 + index + "' not in range [0.."
249 + (this._sequenceList.size() - 1) + "]");
252 return (jalview.binding.Sequence) _sequenceList.get(index);
256 * Method getSequence.Returns the contents of the collection in an Array.
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.
262 * @return this collection as an Array
264 public jalview.binding.Sequence[] getSequence()
266 jalview.binding.Sequence[] array = new jalview.binding.Sequence[0];
267 return (jalview.binding.Sequence[]) this._sequenceList.toArray(array);
271 * Method getSequenceCount.
273 * @return the size of this collection
275 public int getSequenceCount()
277 return this._sequenceList.size();
283 * @return true if at least one Aligned has been added
285 public boolean hasAligned()
287 return this._has_aligned;
291 * Returns the value of field 'aligned'.
293 * @return the value of field 'Aligned'.
295 public boolean isAligned()
297 return this._aligned;
303 * @return true if this object is valid according to the schema
305 public boolean isValid()
310 } catch (org.exolab.castor.xml.ValidationException vex)
321 * @throws org.exolab.castor.xml.MarshalException
322 * if object is null or if any SAXException is thrown during
324 * @throws org.exolab.castor.xml.ValidationException
325 * if this object is an invalid instance according to the schema
327 public void marshal(final java.io.Writer out)
328 throws org.exolab.castor.xml.MarshalException,
329 org.exolab.castor.xml.ValidationException
331 Marshaller.marshal(this, out);
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
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
351 Marshaller.marshal(this, handler);
356 public void removeAllAnnotation()
358 this._annotationList.clear();
363 public void removeAllSequence()
365 this._sequenceList.clear();
369 * Method removeAnnotation.
372 * @return true if the object was removed from the collection.
374 public boolean removeAnnotation(
375 final jalview.binding.Annotation vAnnotation)
377 boolean removed = _annotationList.remove(vAnnotation);
382 * Method removeAnnotationAt.
385 * @return the element removed from the collection
387 public jalview.binding.Annotation removeAnnotationAt(final int index)
389 java.lang.Object obj = this._annotationList.remove(index);
390 return (jalview.binding.Annotation) obj;
394 * Method removeSequence.
397 * @return true if the object was removed from the collection.
399 public boolean removeSequence(final jalview.binding.Sequence vSequence)
401 boolean removed = _sequenceList.remove(vSequence);
406 * Method removeSequenceAt.
409 * @return the element removed from the collection
411 public jalview.binding.Sequence removeSequenceAt(final int index)
413 java.lang.Object obj = this._sequenceList.remove(index);
414 return (jalview.binding.Sequence) obj;
418 * Sets the value of field 'aligned'.
421 * the value of field 'aligned'.
423 public void setAligned(final boolean aligned)
425 this._aligned = aligned;
426 this._has_aligned = true;
434 * @throws java.lang.IndexOutOfBoundsException
435 * if the index given is outside the bounds of the collection
437 public void setAnnotation(final int index,
438 final jalview.binding.Annotation vAnnotation)
439 throws java.lang.IndexOutOfBoundsException
441 // check bounds for index
442 if (index < 0 || index >= this._annotationList.size())
444 throw new IndexOutOfBoundsException("setAnnotation: Index value '"
445 + index + "' not in range [0.."
446 + (this._annotationList.size() - 1) + "]");
449 this._annotationList.set(index, vAnnotation);
455 * @param vAnnotationArray
457 public void setAnnotation(
458 final jalview.binding.Annotation[] vAnnotationArray)
461 _annotationList.clear();
463 for (int i = 0; i < vAnnotationArray.length; i++)
465 this._annotationList.add(vAnnotationArray[i]);
470 * Sets the value of field 'gapChar'.
473 * the value of field 'gapChar'.
475 public void setGapChar(final java.lang.String gapChar)
477 this._gapChar = gapChar;
485 * @throws java.lang.IndexOutOfBoundsException
486 * if the index given is outside the bounds of the collection
488 public void setSequence(final int index,
489 final jalview.binding.Sequence vSequence)
490 throws java.lang.IndexOutOfBoundsException
492 // check bounds for index
493 if (index < 0 || index >= this._sequenceList.size())
495 throw new IndexOutOfBoundsException("setSequence: Index value '"
496 + index + "' not in range [0.."
497 + (this._sequenceList.size() - 1) + "]");
500 this._sequenceList.set(index, vSequence);
506 * @param vSequenceArray
508 public void setSequence(final jalview.binding.Sequence[] vSequenceArray)
511 _sequenceList.clear();
513 for (int i = 0; i < vSequenceArray.length; i++)
515 this._sequenceList.add(vSequenceArray[i]);
523 * @throws org.exolab.castor.xml.MarshalException
524 * if object is null or if any SAXException is thrown during
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
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
535 return (jalview.binding.SequenceSet) Unmarshaller.unmarshal(
536 jalview.binding.SequenceSet.class, reader);
542 * @throws org.exolab.castor.xml.ValidationException
543 * if this object is an invalid instance according to the schema
545 public void validate() throws org.exolab.castor.xml.ValidationException
547 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
548 validator.validate(this);