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 JSeq implements java.io.Serializable
35 // --------------------------/
36 // - Class/Member Variables -/
37 // --------------------------/
45 * keeps track of state for field: _colour
47 private boolean _has_colour;
55 * keeps track of state for field: _start
57 private boolean _has_start;
65 * keeps track of state for field: _end
67 private boolean _has_end;
75 * keeps track of state for field: _id
77 private boolean _has_id;
80 * Field _featuresList.
82 private java.util.Vector _featuresList;
87 private java.util.Vector _pdbidsList;
96 this._featuresList = new java.util.Vector();
97 this._pdbidsList = new java.util.Vector();
108 * @throws java.lang.IndexOutOfBoundsException
109 * if the index given is outside the bounds of the collection
111 public void addFeatures(final jalview.binding.Features vFeatures)
112 throws java.lang.IndexOutOfBoundsException
114 this._featuresList.addElement(vFeatures);
122 * @throws java.lang.IndexOutOfBoundsException
123 * if the index given is outside the bounds of the collection
125 public void addFeatures(final int index,
126 final jalview.binding.Features vFeatures)
127 throws java.lang.IndexOutOfBoundsException
129 this._featuresList.add(index, vFeatures);
136 * @throws java.lang.IndexOutOfBoundsException
137 * if the index given is outside the bounds of the collection
139 public void addPdbids(final jalview.binding.Pdbids vPdbids)
140 throws java.lang.IndexOutOfBoundsException
142 this._pdbidsList.addElement(vPdbids);
150 * @throws java.lang.IndexOutOfBoundsException
151 * if the index given is outside the bounds of the collection
153 public void addPdbids(final int index,
154 final jalview.binding.Pdbids vPdbids)
155 throws java.lang.IndexOutOfBoundsException
157 this._pdbidsList.add(index, vPdbids);
162 public void deleteColour()
164 this._has_colour = false;
169 public void deleteEnd()
171 this._has_end = false;
176 public void deleteId()
178 this._has_id = false;
183 public void deleteStart()
185 this._has_start = false;
189 * Method enumerateFeatures.
191 * @return an Enumeration over all jalview.binding.Features elements
193 public java.util.Enumeration enumerateFeatures()
195 return this._featuresList.elements();
199 * Method enumeratePdbids.
201 * @return an Enumeration over all jalview.binding.Pdbids elements
203 public java.util.Enumeration enumeratePdbids()
205 return this._pdbidsList.elements();
209 * Returns the value of field 'colour'.
211 * @return the value of field 'Colour'.
213 public int getColour()
219 * Returns the value of field 'end'.
221 * @return the value of field 'End'.
229 * Method getFeatures.
232 * @throws java.lang.IndexOutOfBoundsException
233 * if the index given is outside the bounds of the collection
234 * @return the value of the jalview.binding.Features at the given index
236 public jalview.binding.Features getFeatures(final int index)
237 throws java.lang.IndexOutOfBoundsException
239 // check bounds for index
240 if (index < 0 || index >= this._featuresList.size())
242 throw new IndexOutOfBoundsException("getFeatures: Index value '"
243 + index + "' not in range [0.."
244 + (this._featuresList.size() - 1) + "]");
247 return (jalview.binding.Features) _featuresList.get(index);
251 * Method getFeatures.Returns the contents of the collection in an Array.
253 * Note: Just in case the collection contents are changing in another thread,
254 * we pass a 0-length Array of the correct type into the API call. This way we
255 * <i>know</i> that the Array returned is of exactly the correct length.
257 * @return this collection as an Array
259 public jalview.binding.Features[] getFeatures()
261 jalview.binding.Features[] array = new jalview.binding.Features[0];
262 return (jalview.binding.Features[]) this._featuresList.toArray(array);
266 * Method getFeaturesCount.
268 * @return the size of this collection
270 public int getFeaturesCount()
272 return this._featuresList.size();
276 * Returns the value of field 'id'.
278 * @return the value of field 'Id'.
289 * @throws java.lang.IndexOutOfBoundsException
290 * if the index given is outside the bounds of the collection
291 * @return the value of the jalview.binding.Pdbids at the given index
293 public jalview.binding.Pdbids getPdbids(final int index)
294 throws java.lang.IndexOutOfBoundsException
296 // check bounds for index
297 if (index < 0 || index >= this._pdbidsList.size())
299 throw new IndexOutOfBoundsException("getPdbids: Index value '"
300 + index + "' not in range [0.."
301 + (this._pdbidsList.size() - 1) + "]");
304 return (jalview.binding.Pdbids) _pdbidsList.get(index);
308 * Method getPdbids.Returns the contents of the collection in an Array.
310 * Note: Just in case the collection contents are changing in another thread,
311 * we pass a 0-length Array of the correct type into the API call. This way we
312 * <i>know</i> that the Array returned is of exactly the correct length.
314 * @return this collection as an Array
316 public jalview.binding.Pdbids[] getPdbids()
318 jalview.binding.Pdbids[] array = new jalview.binding.Pdbids[0];
319 return (jalview.binding.Pdbids[]) this._pdbidsList.toArray(array);
323 * Method getPdbidsCount.
325 * @return the size of this collection
327 public int getPdbidsCount()
329 return this._pdbidsList.size();
333 * Returns the value of field 'start'.
335 * @return the value of field 'Start'.
337 public int getStart()
345 * @return true if at least one Colour has been added
347 public boolean hasColour()
349 return this._has_colour;
355 * @return true if at least one End has been added
357 public boolean hasEnd()
359 return this._has_end;
365 * @return true if at least one Id has been added
367 public boolean hasId()
375 * @return true if at least one Start has been added
377 public boolean hasStart()
379 return this._has_start;
385 * @return true if this object is valid according to the schema
387 public boolean isValid()
392 } catch (org.exolab.castor.xml.ValidationException vex)
403 * @throws org.exolab.castor.xml.MarshalException
404 * if object is null or if any SAXException is thrown during
406 * @throws org.exolab.castor.xml.ValidationException
407 * if this object is an invalid instance according to the schema
409 public void marshal(final java.io.Writer out)
410 throws org.exolab.castor.xml.MarshalException,
411 org.exolab.castor.xml.ValidationException
413 Marshaller.marshal(this, out);
420 * @throws java.io.IOException
421 * if an IOException occurs during marshaling
422 * @throws org.exolab.castor.xml.ValidationException
423 * if this object is an invalid instance according to the schema
424 * @throws org.exolab.castor.xml.MarshalException
425 * if object is null or if any SAXException is thrown during
428 public void marshal(final org.xml.sax.ContentHandler handler)
429 throws java.io.IOException,
430 org.exolab.castor.xml.MarshalException,
431 org.exolab.castor.xml.ValidationException
433 Marshaller.marshal(this, handler);
438 public void removeAllFeatures()
440 this._featuresList.clear();
445 public void removeAllPdbids()
447 this._pdbidsList.clear();
451 * Method removeFeatures.
454 * @return true if the object was removed from the collection.
456 public boolean removeFeatures(final jalview.binding.Features vFeatures)
458 boolean removed = _featuresList.remove(vFeatures);
463 * Method removeFeaturesAt.
466 * @return the element removed from the collection
468 public jalview.binding.Features removeFeaturesAt(final int index)
470 java.lang.Object obj = this._featuresList.remove(index);
471 return (jalview.binding.Features) obj;
475 * Method removePdbids.
478 * @return true if the object was removed from the collection.
480 public boolean removePdbids(final jalview.binding.Pdbids vPdbids)
482 boolean removed = _pdbidsList.remove(vPdbids);
487 * Method removePdbidsAt.
490 * @return the element removed from the collection
492 public jalview.binding.Pdbids removePdbidsAt(final int index)
494 java.lang.Object obj = this._pdbidsList.remove(index);
495 return (jalview.binding.Pdbids) obj;
499 * Sets the value of field 'colour'.
502 * the value of field 'colour'.
504 public void setColour(final int colour)
506 this._colour = colour;
507 this._has_colour = true;
511 * Sets the value of field 'end'.
514 * the value of field 'end'.
516 public void setEnd(final int end)
519 this._has_end = true;
527 * @throws java.lang.IndexOutOfBoundsException
528 * if the index given is outside the bounds of the collection
530 public void setFeatures(final int index,
531 final jalview.binding.Features vFeatures)
532 throws java.lang.IndexOutOfBoundsException
534 // check bounds for index
535 if (index < 0 || index >= this._featuresList.size())
537 throw new IndexOutOfBoundsException("setFeatures: Index value '"
538 + index + "' not in range [0.."
539 + (this._featuresList.size() - 1) + "]");
542 this._featuresList.set(index, vFeatures);
548 * @param vFeaturesArray
550 public void setFeatures(final jalview.binding.Features[] vFeaturesArray)
553 _featuresList.clear();
555 for (int i = 0; i < vFeaturesArray.length; i++)
557 this._featuresList.add(vFeaturesArray[i]);
562 * Sets the value of field 'id'.
565 * the value of field 'id'.
567 public void setId(final int id)
578 * @throws java.lang.IndexOutOfBoundsException
579 * if the index given is outside the bounds of the collection
581 public void setPdbids(final int index,
582 final jalview.binding.Pdbids vPdbids)
583 throws java.lang.IndexOutOfBoundsException
585 // check bounds for index
586 if (index < 0 || index >= this._pdbidsList.size())
588 throw new IndexOutOfBoundsException("setPdbids: Index value '"
589 + index + "' not in range [0.."
590 + (this._pdbidsList.size() - 1) + "]");
593 this._pdbidsList.set(index, vPdbids);
599 * @param vPdbidsArray
601 public void setPdbids(final jalview.binding.Pdbids[] vPdbidsArray)
606 for (int i = 0; i < vPdbidsArray.length; i++)
608 this._pdbidsList.add(vPdbidsArray[i]);
613 * Sets the value of field 'start'.
616 * the value of field 'start'.
618 public void setStart(final int start)
621 this._has_start = true;
628 * @throws org.exolab.castor.xml.MarshalException
629 * if object is null or if any SAXException is thrown during
631 * @throws org.exolab.castor.xml.ValidationException
632 * if this object is an invalid instance according to the schema
633 * @return the unmarshaled jalview.binding.JSeq
635 public static jalview.binding.JSeq unmarshal(final java.io.Reader reader)
636 throws org.exolab.castor.xml.MarshalException,
637 org.exolab.castor.xml.ValidationException
639 return (jalview.binding.JSeq) Unmarshaller.unmarshal(
640 jalview.binding.JSeq.class, reader);
646 * @throws org.exolab.castor.xml.ValidationException
647 * if this object is an invalid instance according to the schema
649 public void validate() throws org.exolab.castor.xml.ValidationException
651 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
652 validator.validate(this);