2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 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;
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
326 public void marshal(final java.io.Writer out)
327 throws org.exolab.castor.xml.MarshalException,
328 org.exolab.castor.xml.ValidationException
330 Marshaller.marshal(this, out);
337 * @throws java.io.IOException
338 * if an IOException occurs during marshaling
339 * @throws org.exolab.castor.xml.ValidationException
340 * if this object is an invalid instance according to the
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
529 * @return the unmarshaled jalview.binding.SequenceSet
531 public static jalview.binding.SequenceSet unmarshal(
532 final java.io.Reader reader)
533 throws org.exolab.castor.xml.MarshalException,
534 org.exolab.castor.xml.ValidationException
536 return (jalview.binding.SequenceSet) Unmarshaller.unmarshal(
537 jalview.binding.SequenceSet.class, reader);
543 * @throws org.exolab.castor.xml.ValidationException
544 * if this object is an invalid instance according to the
547 public void validate() throws org.exolab.castor.xml.ValidationException
549 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
550 validator.validate(this);