2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3 * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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/>.
18 package jalview.binding;
20 //---------------------------------/
21 //- Imported classes and packages -/
22 //---------------------------------/
24 import org.exolab.castor.xml.Marshaller;
25 import org.exolab.castor.xml.Unmarshaller;
30 * @version $Revision$ $Date$
32 public class SequenceSet implements java.io.Serializable
35 // --------------------------/
36 // - Class/Member Variables -/
37 // --------------------------/
42 private java.lang.String _gapChar;
47 private boolean _aligned;
50 * keeps track of state for field: _aligned
52 private boolean _has_aligned;
55 * Field _sequenceList.
57 private java.util.Vector _sequenceList;
60 * Field _annotationList.
62 private java.util.Vector _annotationList;
71 this._sequenceList = new java.util.Vector();
72 this._annotationList = new java.util.Vector();
83 * @throws java.lang.IndexOutOfBoundsException
84 * if the index given is outside the bounds of the collection
86 public void addAnnotation(final jalview.binding.Annotation vAnnotation)
87 throws java.lang.IndexOutOfBoundsException
89 this._annotationList.addElement(vAnnotation);
97 * @throws java.lang.IndexOutOfBoundsException
98 * if the index given is outside the bounds of the collection
100 public void addAnnotation(final int index,
101 final jalview.binding.Annotation vAnnotation)
102 throws java.lang.IndexOutOfBoundsException
104 this._annotationList.add(index, vAnnotation);
111 * @throws java.lang.IndexOutOfBoundsException
112 * if the index given is outside the bounds of the collection
114 public void addSequence(final jalview.binding.Sequence vSequence)
115 throws java.lang.IndexOutOfBoundsException
117 this._sequenceList.addElement(vSequence);
125 * @throws java.lang.IndexOutOfBoundsException
126 * if the index given is outside the bounds of the collection
128 public void addSequence(final int index,
129 final jalview.binding.Sequence vSequence)
130 throws java.lang.IndexOutOfBoundsException
132 this._sequenceList.add(index, vSequence);
137 public void deleteAligned()
139 this._has_aligned = false;
143 * Method enumerateAnnotation.
145 * @return an Enumeration over all jalview.binding.Annotation elements
147 public java.util.Enumeration enumerateAnnotation()
149 return this._annotationList.elements();
153 * Method enumerateSequence.
155 * @return an Enumeration over all jalview.binding.Sequence elements
157 public java.util.Enumeration enumerateSequence()
159 return this._sequenceList.elements();
163 * Returns the value of field 'aligned'.
165 * @return the value of field 'Aligned'.
167 public boolean getAligned()
169 return this._aligned;
173 * Method getAnnotation.
176 * @throws java.lang.IndexOutOfBoundsException
177 * if the index given is outside the bounds of the collection
178 * @return the value of the jalview.binding.Annotation at the given index
180 public jalview.binding.Annotation getAnnotation(final int index)
181 throws java.lang.IndexOutOfBoundsException
183 // check bounds for index
184 if (index < 0 || index >= this._annotationList.size())
186 throw new IndexOutOfBoundsException("getAnnotation: Index value '"
187 + index + "' not in range [0.."
188 + (this._annotationList.size() - 1) + "]");
191 return (jalview.binding.Annotation) _annotationList.get(index);
195 * Method getAnnotation.Returns the contents of the collection in an Array.
197 * Note: Just in case the collection contents are changing in another thread,
198 * we pass a 0-length Array of the correct type into the API call. This way we
199 * <i>know</i> that the Array returned is of exactly the correct length.
201 * @return this collection as an Array
203 public jalview.binding.Annotation[] getAnnotation()
205 jalview.binding.Annotation[] array = new jalview.binding.Annotation[0];
206 return (jalview.binding.Annotation[]) this._annotationList
211 * Method getAnnotationCount.
213 * @return the size of this collection
215 public int getAnnotationCount()
217 return this._annotationList.size();
221 * Returns the value of field 'gapChar'.
223 * @return the value of field 'GapChar'.
225 public java.lang.String getGapChar()
227 return this._gapChar;
231 * Method getSequence.
234 * @throws java.lang.IndexOutOfBoundsException
235 * if the index given is outside the bounds of the collection
236 * @return the value of the jalview.binding.Sequence at the given index
238 public jalview.binding.Sequence getSequence(final int index)
239 throws java.lang.IndexOutOfBoundsException
241 // check bounds for index
242 if (index < 0 || index >= this._sequenceList.size())
244 throw new IndexOutOfBoundsException("getSequence: Index value '"
245 + index + "' not in range [0.."
246 + (this._sequenceList.size() - 1) + "]");
249 return (jalview.binding.Sequence) _sequenceList.get(index);
253 * Method getSequence.Returns the contents of the collection in an Array.
255 * Note: Just in case the collection contents are changing in another thread,
256 * we pass a 0-length Array of the correct type into the API call. This way we
257 * <i>know</i> that the Array returned is of exactly the correct length.
259 * @return this collection as an Array
261 public jalview.binding.Sequence[] getSequence()
263 jalview.binding.Sequence[] array = new jalview.binding.Sequence[0];
264 return (jalview.binding.Sequence[]) this._sequenceList.toArray(array);
268 * Method getSequenceCount.
270 * @return the size of this collection
272 public int getSequenceCount()
274 return this._sequenceList.size();
280 * @return true if at least one Aligned has been added
282 public boolean hasAligned()
284 return this._has_aligned;
288 * Returns the value of field 'aligned'.
290 * @return the value of field 'Aligned'.
292 public boolean isAligned()
294 return this._aligned;
300 * @return true if this object is valid according to the schema
302 public boolean isValid()
307 } catch (org.exolab.castor.xml.ValidationException vex)
318 * @throws org.exolab.castor.xml.MarshalException
319 * if object is null or if any SAXException is thrown during
321 * @throws org.exolab.castor.xml.ValidationException
322 * if this object is an invalid instance according to the schema
324 public void marshal(final java.io.Writer out)
325 throws org.exolab.castor.xml.MarshalException,
326 org.exolab.castor.xml.ValidationException
328 Marshaller.marshal(this, out);
335 * @throws java.io.IOException
336 * if an IOException occurs during marshaling
337 * @throws org.exolab.castor.xml.ValidationException
338 * if this object is an invalid instance according to the schema
339 * @throws org.exolab.castor.xml.MarshalException
340 * if object is null or if any SAXException is thrown during
343 public void marshal(final org.xml.sax.ContentHandler handler)
344 throws java.io.IOException,
345 org.exolab.castor.xml.MarshalException,
346 org.exolab.castor.xml.ValidationException
348 Marshaller.marshal(this, handler);
353 public void removeAllAnnotation()
355 this._annotationList.clear();
360 public void removeAllSequence()
362 this._sequenceList.clear();
366 * Method removeAnnotation.
369 * @return true if the object was removed from the collection.
371 public boolean removeAnnotation(
372 final jalview.binding.Annotation vAnnotation)
374 boolean removed = _annotationList.remove(vAnnotation);
379 * Method removeAnnotationAt.
382 * @return the element removed from the collection
384 public jalview.binding.Annotation removeAnnotationAt(final int index)
386 java.lang.Object obj = this._annotationList.remove(index);
387 return (jalview.binding.Annotation) obj;
391 * Method removeSequence.
394 * @return true if the object was removed from the collection.
396 public boolean removeSequence(final jalview.binding.Sequence vSequence)
398 boolean removed = _sequenceList.remove(vSequence);
403 * Method removeSequenceAt.
406 * @return the element removed from the collection
408 public jalview.binding.Sequence removeSequenceAt(final int index)
410 java.lang.Object obj = this._sequenceList.remove(index);
411 return (jalview.binding.Sequence) obj;
415 * Sets the value of field 'aligned'.
418 * the value of field 'aligned'.
420 public void setAligned(final boolean aligned)
422 this._aligned = aligned;
423 this._has_aligned = true;
431 * @throws java.lang.IndexOutOfBoundsException
432 * if the index given is outside the bounds of the collection
434 public void setAnnotation(final int index,
435 final jalview.binding.Annotation vAnnotation)
436 throws java.lang.IndexOutOfBoundsException
438 // check bounds for index
439 if (index < 0 || index >= this._annotationList.size())
441 throw new IndexOutOfBoundsException("setAnnotation: Index value '"
442 + index + "' not in range [0.."
443 + (this._annotationList.size() - 1) + "]");
446 this._annotationList.set(index, vAnnotation);
452 * @param vAnnotationArray
454 public void setAnnotation(
455 final jalview.binding.Annotation[] vAnnotationArray)
458 _annotationList.clear();
460 for (int i = 0; i < vAnnotationArray.length; i++)
462 this._annotationList.add(vAnnotationArray[i]);
467 * Sets the value of field 'gapChar'.
470 * the value of field 'gapChar'.
472 public void setGapChar(final java.lang.String gapChar)
474 this._gapChar = gapChar;
482 * @throws java.lang.IndexOutOfBoundsException
483 * if the index given is outside the bounds of the collection
485 public void setSequence(final int index,
486 final jalview.binding.Sequence vSequence)
487 throws java.lang.IndexOutOfBoundsException
489 // check bounds for index
490 if (index < 0 || index >= this._sequenceList.size())
492 throw new IndexOutOfBoundsException("setSequence: Index value '"
493 + index + "' not in range [0.."
494 + (this._sequenceList.size() - 1) + "]");
497 this._sequenceList.set(index, vSequence);
503 * @param vSequenceArray
505 public void setSequence(final jalview.binding.Sequence[] vSequenceArray)
508 _sequenceList.clear();
510 for (int i = 0; i < vSequenceArray.length; i++)
512 this._sequenceList.add(vSequenceArray[i]);
520 * @throws org.exolab.castor.xml.MarshalException
521 * if object is null or if any SAXException is thrown during
523 * @throws org.exolab.castor.xml.ValidationException
524 * if this object is an invalid instance according to the schema
525 * @return the unmarshaled jalview.binding.SequenceSet
527 public static jalview.binding.SequenceSet unmarshal(
528 final java.io.Reader reader)
529 throws org.exolab.castor.xml.MarshalException,
530 org.exolab.castor.xml.ValidationException
532 return (jalview.binding.SequenceSet) Unmarshaller.unmarshal(
533 jalview.binding.SequenceSet.class, reader);
539 * @throws org.exolab.castor.xml.ValidationException
540 * if this object is an invalid instance according to the schema
542 public void validate() throws org.exolab.castor.xml.ValidationException
544 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
545 validator.validate(this);