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 jalview.util.MessageManager;
29 import org.exolab.castor.xml.Marshaller;
30 import org.exolab.castor.xml.Unmarshaller;
35 * @version $Revision$ $Date$
37 public class SequenceSet implements java.io.Serializable
40 // --------------------------/
41 // - Class/Member Variables -/
42 // --------------------------/
47 private java.lang.String _gapChar;
52 private boolean _aligned;
55 * keeps track of state for field: _aligned
57 private boolean _has_aligned;
60 * Field _sequenceList.
62 private java.util.Vector _sequenceList;
65 * Field _annotationList.
67 private java.util.Vector _annotationList;
76 this._sequenceList = new java.util.Vector();
77 this._annotationList = new java.util.Vector();
88 * @throws java.lang.IndexOutOfBoundsException
89 * if the index given is outside the bounds of the collection
91 public void addAnnotation(final jalview.binding.Annotation vAnnotation)
92 throws java.lang.IndexOutOfBoundsException
94 this._annotationList.addElement(vAnnotation);
102 * @throws java.lang.IndexOutOfBoundsException
103 * if the index given is outside the bounds of the collection
105 public void addAnnotation(final int index,
106 final jalview.binding.Annotation vAnnotation)
107 throws java.lang.IndexOutOfBoundsException
109 this._annotationList.add(index, vAnnotation);
116 * @throws java.lang.IndexOutOfBoundsException
117 * if the index given is outside the bounds of the collection
119 public void addSequence(final jalview.binding.Sequence vSequence)
120 throws java.lang.IndexOutOfBoundsException
122 this._sequenceList.addElement(vSequence);
130 * @throws java.lang.IndexOutOfBoundsException
131 * if the index given is outside the bounds of the collection
133 public void addSequence(final int index,
134 final jalview.binding.Sequence vSequence)
135 throws java.lang.IndexOutOfBoundsException
137 this._sequenceList.add(index, vSequence);
142 public void deleteAligned()
144 this._has_aligned = false;
148 * Method enumerateAnnotation.
150 * @return an Enumeration over all jalview.binding.Annotation elements
152 public java.util.Enumeration enumerateAnnotation()
154 return this._annotationList.elements();
158 * Method enumerateSequence.
160 * @return an Enumeration over all jalview.binding.Sequence elements
162 public java.util.Enumeration enumerateSequence()
164 return this._sequenceList.elements();
168 * Returns the value of field 'aligned'.
170 * @return the value of field 'Aligned'.
172 public boolean getAligned()
174 return this._aligned;
178 * Method getAnnotation.
181 * @throws java.lang.IndexOutOfBoundsException
182 * if the index given is outside the bounds of the collection
183 * @return the value of the jalview.binding.Annotation at the given index
185 public jalview.binding.Annotation getAnnotation(final int index)
186 throws java.lang.IndexOutOfBoundsException
188 // check bounds for index
189 if (index < 0 || index >= this._annotationList.size())
191 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
193 Integer.valueOf(index).toString(),
194 Integer.valueOf((this._annotationList.size() - 1)).toString()
198 return (jalview.binding.Annotation) _annotationList.get(index);
202 * Method getAnnotation.Returns the contents of the collection in an Array.
204 * Note: Just in case the collection contents are changing in another thread,
205 * we pass a 0-length Array of the correct type into the API call. This way we
206 * <i>know</i> that the Array returned is of exactly the correct length.
208 * @return this collection as an Array
210 public jalview.binding.Annotation[] getAnnotation()
212 jalview.binding.Annotation[] array = new jalview.binding.Annotation[0];
213 return (jalview.binding.Annotation[]) this._annotationList
218 * Method getAnnotationCount.
220 * @return the size of this collection
222 public int getAnnotationCount()
224 return this._annotationList.size();
228 * Returns the value of field 'gapChar'.
230 * @return the value of field 'GapChar'.
232 public java.lang.String getGapChar()
234 return this._gapChar;
238 * Method getSequence.
241 * @throws java.lang.IndexOutOfBoundsException
242 * if the index given is outside the bounds of the collection
243 * @return the value of the jalview.binding.Sequence at the given index
245 public jalview.binding.Sequence getSequence(final int index)
246 throws java.lang.IndexOutOfBoundsException
248 // check bounds for index
249 if (index < 0 || index >= this._sequenceList.size())
251 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
253 Integer.valueOf(index).toString(),
254 Integer.valueOf((this._sequenceList.size() - 1)).toString()
258 return (jalview.binding.Sequence) _sequenceList.get(index);
262 * Method getSequence.Returns the contents of the collection in an Array.
264 * Note: Just in case the collection contents are changing in another thread,
265 * we pass a 0-length Array of the correct type into the API call. This way we
266 * <i>know</i> that the Array returned is of exactly the correct length.
268 * @return this collection as an Array
270 public jalview.binding.Sequence[] getSequence()
272 jalview.binding.Sequence[] array = new jalview.binding.Sequence[0];
273 return (jalview.binding.Sequence[]) this._sequenceList.toArray(array);
277 * Method getSequenceCount.
279 * @return the size of this collection
281 public int getSequenceCount()
283 return this._sequenceList.size();
289 * @return true if at least one Aligned has been added
291 public boolean hasAligned()
293 return this._has_aligned;
297 * Returns the value of field 'aligned'.
299 * @return the value of field 'Aligned'.
301 public boolean isAligned()
303 return this._aligned;
309 * @return true if this object is valid according to the schema
311 public boolean isValid()
316 } catch (org.exolab.castor.xml.ValidationException vex)
327 * @throws org.exolab.castor.xml.MarshalException
328 * if object is null or if any SAXException is thrown during
330 * @throws org.exolab.castor.xml.ValidationException
331 * if this object is an invalid instance according to the schema
333 public void marshal(final java.io.Writer out)
334 throws org.exolab.castor.xml.MarshalException,
335 org.exolab.castor.xml.ValidationException
337 Marshaller.marshal(this, out);
344 * @throws java.io.IOException
345 * if an IOException occurs during marshaling
346 * @throws org.exolab.castor.xml.ValidationException
347 * if this object is an invalid instance according to the schema
348 * @throws org.exolab.castor.xml.MarshalException
349 * if object is null or if any SAXException is thrown during
352 public void marshal(final org.xml.sax.ContentHandler handler)
353 throws java.io.IOException,
354 org.exolab.castor.xml.MarshalException,
355 org.exolab.castor.xml.ValidationException
357 Marshaller.marshal(this, handler);
362 public void removeAllAnnotation()
364 this._annotationList.clear();
369 public void removeAllSequence()
371 this._sequenceList.clear();
375 * Method removeAnnotation.
378 * @return true if the object was removed from the collection.
380 public boolean removeAnnotation(
381 final jalview.binding.Annotation vAnnotation)
383 boolean removed = _annotationList.remove(vAnnotation);
388 * Method removeAnnotationAt.
391 * @return the element removed from the collection
393 public jalview.binding.Annotation removeAnnotationAt(final int index)
395 java.lang.Object obj = this._annotationList.remove(index);
396 return (jalview.binding.Annotation) obj;
400 * Method removeSequence.
403 * @return true if the object was removed from the collection.
405 public boolean removeSequence(final jalview.binding.Sequence vSequence)
407 boolean removed = _sequenceList.remove(vSequence);
412 * Method removeSequenceAt.
415 * @return the element removed from the collection
417 public jalview.binding.Sequence removeSequenceAt(final int index)
419 java.lang.Object obj = this._sequenceList.remove(index);
420 return (jalview.binding.Sequence) obj;
424 * Sets the value of field 'aligned'.
427 * the value of field 'aligned'.
429 public void setAligned(final boolean aligned)
431 this._aligned = aligned;
432 this._has_aligned = true;
440 * @throws java.lang.IndexOutOfBoundsException
441 * if the index given is outside the bounds of the collection
443 public void setAnnotation(final int index,
444 final jalview.binding.Annotation vAnnotation)
445 throws java.lang.IndexOutOfBoundsException
447 // check bounds for index
448 if (index < 0 || index >= this._annotationList.size())
450 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
452 Integer.valueOf(index).toString(),
453 Integer.valueOf((this._annotationList.size() - 1)).toString()
457 this._annotationList.set(index, vAnnotation);
463 * @param vAnnotationArray
465 public void setAnnotation(
466 final jalview.binding.Annotation[] vAnnotationArray)
469 _annotationList.clear();
471 for (int i = 0; i < vAnnotationArray.length; i++)
473 this._annotationList.add(vAnnotationArray[i]);
478 * Sets the value of field 'gapChar'.
481 * the value of field 'gapChar'.
483 public void setGapChar(final java.lang.String gapChar)
485 this._gapChar = gapChar;
493 * @throws java.lang.IndexOutOfBoundsException
494 * if the index given is outside the bounds of the collection
496 public void setSequence(final int index,
497 final jalview.binding.Sequence vSequence)
498 throws java.lang.IndexOutOfBoundsException
500 // check bounds for index
501 if (index < 0 || index >= this._sequenceList.size())
503 throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
505 Integer.valueOf(index).toString(),
506 Integer.valueOf((this._sequenceList.size() - 1)).toString()
510 this._sequenceList.set(index, vSequence);
516 * @param vSequenceArray
518 public void setSequence(final jalview.binding.Sequence[] vSequenceArray)
521 _sequenceList.clear();
523 for (int i = 0; i < vSequenceArray.length; i++)
525 this._sequenceList.add(vSequenceArray[i]);
533 * @throws org.exolab.castor.xml.MarshalException
534 * if object is null or if any SAXException is thrown during
536 * @throws org.exolab.castor.xml.ValidationException
537 * if this object is an invalid instance according to the schema
538 * @return the unmarshaled jalview.binding.SequenceSet
540 public static jalview.binding.SequenceSet unmarshal(
541 final java.io.Reader reader)
542 throws org.exolab.castor.xml.MarshalException,
543 org.exolab.castor.xml.ValidationException
545 return (jalview.binding.SequenceSet) Unmarshaller.unmarshal(
546 jalview.binding.SequenceSet.class, reader);
552 * @throws org.exolab.castor.xml.ValidationException
553 * if this object is an invalid instance according to the schema
555 public void validate() throws org.exolab.castor.xml.ValidationException
557 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
558 validator.validate(this);