JAL-1503 update version in GPL header
[jalview.git] / src / jalview / binding / JSeq.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.1)
3  * Copyright (C) 2014 The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
10  *  
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.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  * The Jalview Authors are detailed in the 'AUTHORS' file.
18  */
19 package jalview.binding;
20
21 //---------------------------------/
22 //- Imported classes and packages -/
23 //---------------------------------/
24
25 import org.exolab.castor.xml.Marshaller;
26 import org.exolab.castor.xml.Unmarshaller;
27
28 /**
29  * Class JSeq.
30  * 
31  * @version $Revision$ $Date$
32  */
33 public class JSeq implements java.io.Serializable
34 {
35
36   // --------------------------/
37   // - Class/Member Variables -/
38   // --------------------------/
39
40   /**
41    * Field _colour.
42    */
43   private int _colour;
44
45   /**
46    * keeps track of state for field: _colour
47    */
48   private boolean _has_colour;
49
50   /**
51    * Field _start.
52    */
53   private int _start;
54
55   /**
56    * keeps track of state for field: _start
57    */
58   private boolean _has_start;
59
60   /**
61    * Field _end.
62    */
63   private int _end;
64
65   /**
66    * keeps track of state for field: _end
67    */
68   private boolean _has_end;
69
70   /**
71    * Field _id.
72    */
73   private int _id;
74
75   /**
76    * keeps track of state for field: _id
77    */
78   private boolean _has_id;
79
80   /**
81    * Field _featuresList.
82    */
83   private java.util.Vector _featuresList;
84
85   /**
86    * Field _pdbidsList.
87    */
88   private java.util.Vector _pdbidsList;
89
90   // ----------------/
91   // - Constructors -/
92   // ----------------/
93
94   public JSeq()
95   {
96     super();
97     this._featuresList = new java.util.Vector();
98     this._pdbidsList = new java.util.Vector();
99   }
100
101   // -----------/
102   // - Methods -/
103   // -----------/
104
105   /**
106    * 
107    * 
108    * @param vFeatures
109    * @throws java.lang.IndexOutOfBoundsException
110    *           if the index given is outside the bounds of the collection
111    */
112   public void addFeatures(final jalview.binding.Features vFeatures)
113           throws java.lang.IndexOutOfBoundsException
114   {
115     this._featuresList.addElement(vFeatures);
116   }
117
118   /**
119    * 
120    * 
121    * @param index
122    * @param vFeatures
123    * @throws java.lang.IndexOutOfBoundsException
124    *           if the index given is outside the bounds of the collection
125    */
126   public void addFeatures(final int index,
127           final jalview.binding.Features vFeatures)
128           throws java.lang.IndexOutOfBoundsException
129   {
130     this._featuresList.add(index, vFeatures);
131   }
132
133   /**
134    * 
135    * 
136    * @param vPdbids
137    * @throws java.lang.IndexOutOfBoundsException
138    *           if the index given is outside the bounds of the collection
139    */
140   public void addPdbids(final jalview.binding.Pdbids vPdbids)
141           throws java.lang.IndexOutOfBoundsException
142   {
143     this._pdbidsList.addElement(vPdbids);
144   }
145
146   /**
147    * 
148    * 
149    * @param index
150    * @param vPdbids
151    * @throws java.lang.IndexOutOfBoundsException
152    *           if the index given is outside the bounds of the collection
153    */
154   public void addPdbids(final int index,
155           final jalview.binding.Pdbids vPdbids)
156           throws java.lang.IndexOutOfBoundsException
157   {
158     this._pdbidsList.add(index, vPdbids);
159   }
160
161   /**
162      */
163   public void deleteColour()
164   {
165     this._has_colour = false;
166   }
167
168   /**
169      */
170   public void deleteEnd()
171   {
172     this._has_end = false;
173   }
174
175   /**
176      */
177   public void deleteId()
178   {
179     this._has_id = false;
180   }
181
182   /**
183      */
184   public void deleteStart()
185   {
186     this._has_start = false;
187   }
188
189   /**
190    * Method enumerateFeatures.
191    * 
192    * @return an Enumeration over all jalview.binding.Features elements
193    */
194   public java.util.Enumeration enumerateFeatures()
195   {
196     return this._featuresList.elements();
197   }
198
199   /**
200    * Method enumeratePdbids.
201    * 
202    * @return an Enumeration over all jalview.binding.Pdbids elements
203    */
204   public java.util.Enumeration enumeratePdbids()
205   {
206     return this._pdbidsList.elements();
207   }
208
209   /**
210    * Returns the value of field 'colour'.
211    * 
212    * @return the value of field 'Colour'.
213    */
214   public int getColour()
215   {
216     return this._colour;
217   }
218
219   /**
220    * Returns the value of field 'end'.
221    * 
222    * @return the value of field 'End'.
223    */
224   public int getEnd()
225   {
226     return this._end;
227   }
228
229   /**
230    * Method getFeatures.
231    * 
232    * @param index
233    * @throws java.lang.IndexOutOfBoundsException
234    *           if the index given is outside the bounds of the collection
235    * @return the value of the jalview.binding.Features at the given index
236    */
237   public jalview.binding.Features getFeatures(final int index)
238           throws java.lang.IndexOutOfBoundsException
239   {
240     // check bounds for index
241     if (index < 0 || index >= this._featuresList.size())
242     {
243       throw new IndexOutOfBoundsException("getFeatures: Index value '"
244               + index + "' not in range [0.."
245               + (this._featuresList.size() - 1) + "]");
246     }
247
248     return (jalview.binding.Features) _featuresList.get(index);
249   }
250
251   /**
252    * Method getFeatures.Returns the contents of the collection in an Array.
253    * <p>
254    * Note: Just in case the collection contents are changing in another thread,
255    * we pass a 0-length Array of the correct type into the API call. This way we
256    * <i>know</i> that the Array returned is of exactly the correct length.
257    * 
258    * @return this collection as an Array
259    */
260   public jalview.binding.Features[] getFeatures()
261   {
262     jalview.binding.Features[] array = new jalview.binding.Features[0];
263     return (jalview.binding.Features[]) this._featuresList.toArray(array);
264   }
265
266   /**
267    * Method getFeaturesCount.
268    * 
269    * @return the size of this collection
270    */
271   public int getFeaturesCount()
272   {
273     return this._featuresList.size();
274   }
275
276   /**
277    * Returns the value of field 'id'.
278    * 
279    * @return the value of field 'Id'.
280    */
281   public int getId()
282   {
283     return this._id;
284   }
285
286   /**
287    * Method getPdbids.
288    * 
289    * @param index
290    * @throws java.lang.IndexOutOfBoundsException
291    *           if the index given is outside the bounds of the collection
292    * @return the value of the jalview.binding.Pdbids at the given index
293    */
294   public jalview.binding.Pdbids getPdbids(final int index)
295           throws java.lang.IndexOutOfBoundsException
296   {
297     // check bounds for index
298     if (index < 0 || index >= this._pdbidsList.size())
299     {
300       throw new IndexOutOfBoundsException("getPdbids: Index value '"
301               + index + "' not in range [0.."
302               + (this._pdbidsList.size() - 1) + "]");
303     }
304
305     return (jalview.binding.Pdbids) _pdbidsList.get(index);
306   }
307
308   /**
309    * Method getPdbids.Returns the contents of the collection in an Array.
310    * <p>
311    * Note: Just in case the collection contents are changing in another thread,
312    * we pass a 0-length Array of the correct type into the API call. This way we
313    * <i>know</i> that the Array returned is of exactly the correct length.
314    * 
315    * @return this collection as an Array
316    */
317   public jalview.binding.Pdbids[] getPdbids()
318   {
319     jalview.binding.Pdbids[] array = new jalview.binding.Pdbids[0];
320     return (jalview.binding.Pdbids[]) this._pdbidsList.toArray(array);
321   }
322
323   /**
324    * Method getPdbidsCount.
325    * 
326    * @return the size of this collection
327    */
328   public int getPdbidsCount()
329   {
330     return this._pdbidsList.size();
331   }
332
333   /**
334    * Returns the value of field 'start'.
335    * 
336    * @return the value of field 'Start'.
337    */
338   public int getStart()
339   {
340     return this._start;
341   }
342
343   /**
344    * Method hasColour.
345    * 
346    * @return true if at least one Colour has been added
347    */
348   public boolean hasColour()
349   {
350     return this._has_colour;
351   }
352
353   /**
354    * Method hasEnd.
355    * 
356    * @return true if at least one End has been added
357    */
358   public boolean hasEnd()
359   {
360     return this._has_end;
361   }
362
363   /**
364    * Method hasId.
365    * 
366    * @return true if at least one Id has been added
367    */
368   public boolean hasId()
369   {
370     return this._has_id;
371   }
372
373   /**
374    * Method hasStart.
375    * 
376    * @return true if at least one Start has been added
377    */
378   public boolean hasStart()
379   {
380     return this._has_start;
381   }
382
383   /**
384    * Method isValid.
385    * 
386    * @return true if this object is valid according to the schema
387    */
388   public boolean isValid()
389   {
390     try
391     {
392       validate();
393     } catch (org.exolab.castor.xml.ValidationException vex)
394     {
395       return false;
396     }
397     return true;
398   }
399
400   /**
401    * 
402    * 
403    * @param out
404    * @throws org.exolab.castor.xml.MarshalException
405    *           if object is null or if any SAXException is thrown during
406    *           marshaling
407    * @throws org.exolab.castor.xml.ValidationException
408    *           if this object is an invalid instance according to the schema
409    */
410   public void marshal(final java.io.Writer out)
411           throws org.exolab.castor.xml.MarshalException,
412           org.exolab.castor.xml.ValidationException
413   {
414     Marshaller.marshal(this, out);
415   }
416
417   /**
418    * 
419    * 
420    * @param handler
421    * @throws java.io.IOException
422    *           if an IOException occurs during marshaling
423    * @throws org.exolab.castor.xml.ValidationException
424    *           if this object is an invalid instance according to the schema
425    * @throws org.exolab.castor.xml.MarshalException
426    *           if object is null or if any SAXException is thrown during
427    *           marshaling
428    */
429   public void marshal(final org.xml.sax.ContentHandler handler)
430           throws java.io.IOException,
431           org.exolab.castor.xml.MarshalException,
432           org.exolab.castor.xml.ValidationException
433   {
434     Marshaller.marshal(this, handler);
435   }
436
437   /**
438      */
439   public void removeAllFeatures()
440   {
441     this._featuresList.clear();
442   }
443
444   /**
445      */
446   public void removeAllPdbids()
447   {
448     this._pdbidsList.clear();
449   }
450
451   /**
452    * Method removeFeatures.
453    * 
454    * @param vFeatures
455    * @return true if the object was removed from the collection.
456    */
457   public boolean removeFeatures(final jalview.binding.Features vFeatures)
458   {
459     boolean removed = _featuresList.remove(vFeatures);
460     return removed;
461   }
462
463   /**
464    * Method removeFeaturesAt.
465    * 
466    * @param index
467    * @return the element removed from the collection
468    */
469   public jalview.binding.Features removeFeaturesAt(final int index)
470   {
471     java.lang.Object obj = this._featuresList.remove(index);
472     return (jalview.binding.Features) obj;
473   }
474
475   /**
476    * Method removePdbids.
477    * 
478    * @param vPdbids
479    * @return true if the object was removed from the collection.
480    */
481   public boolean removePdbids(final jalview.binding.Pdbids vPdbids)
482   {
483     boolean removed = _pdbidsList.remove(vPdbids);
484     return removed;
485   }
486
487   /**
488    * Method removePdbidsAt.
489    * 
490    * @param index
491    * @return the element removed from the collection
492    */
493   public jalview.binding.Pdbids removePdbidsAt(final int index)
494   {
495     java.lang.Object obj = this._pdbidsList.remove(index);
496     return (jalview.binding.Pdbids) obj;
497   }
498
499   /**
500    * Sets the value of field 'colour'.
501    * 
502    * @param colour
503    *          the value of field 'colour'.
504    */
505   public void setColour(final int colour)
506   {
507     this._colour = colour;
508     this._has_colour = true;
509   }
510
511   /**
512    * Sets the value of field 'end'.
513    * 
514    * @param end
515    *          the value of field 'end'.
516    */
517   public void setEnd(final int end)
518   {
519     this._end = end;
520     this._has_end = true;
521   }
522
523   /**
524    * 
525    * 
526    * @param index
527    * @param vFeatures
528    * @throws java.lang.IndexOutOfBoundsException
529    *           if the index given is outside the bounds of the collection
530    */
531   public void setFeatures(final int index,
532           final jalview.binding.Features vFeatures)
533           throws java.lang.IndexOutOfBoundsException
534   {
535     // check bounds for index
536     if (index < 0 || index >= this._featuresList.size())
537     {
538       throw new IndexOutOfBoundsException("setFeatures: Index value '"
539               + index + "' not in range [0.."
540               + (this._featuresList.size() - 1) + "]");
541     }
542
543     this._featuresList.set(index, vFeatures);
544   }
545
546   /**
547    * 
548    * 
549    * @param vFeaturesArray
550    */
551   public void setFeatures(final jalview.binding.Features[] vFeaturesArray)
552   {
553     // -- copy array
554     _featuresList.clear();
555
556     for (int i = 0; i < vFeaturesArray.length; i++)
557     {
558       this._featuresList.add(vFeaturesArray[i]);
559     }
560   }
561
562   /**
563    * Sets the value of field 'id'.
564    * 
565    * @param id
566    *          the value of field 'id'.
567    */
568   public void setId(final int id)
569   {
570     this._id = id;
571     this._has_id = true;
572   }
573
574   /**
575    * 
576    * 
577    * @param index
578    * @param vPdbids
579    * @throws java.lang.IndexOutOfBoundsException
580    *           if the index given is outside the bounds of the collection
581    */
582   public void setPdbids(final int index,
583           final jalview.binding.Pdbids vPdbids)
584           throws java.lang.IndexOutOfBoundsException
585   {
586     // check bounds for index
587     if (index < 0 || index >= this._pdbidsList.size())
588     {
589       throw new IndexOutOfBoundsException("setPdbids: Index value '"
590               + index + "' not in range [0.."
591               + (this._pdbidsList.size() - 1) + "]");
592     }
593
594     this._pdbidsList.set(index, vPdbids);
595   }
596
597   /**
598    * 
599    * 
600    * @param vPdbidsArray
601    */
602   public void setPdbids(final jalview.binding.Pdbids[] vPdbidsArray)
603   {
604     // -- copy array
605     _pdbidsList.clear();
606
607     for (int i = 0; i < vPdbidsArray.length; i++)
608     {
609       this._pdbidsList.add(vPdbidsArray[i]);
610     }
611   }
612
613   /**
614    * Sets the value of field 'start'.
615    * 
616    * @param start
617    *          the value of field 'start'.
618    */
619   public void setStart(final int start)
620   {
621     this._start = start;
622     this._has_start = true;
623   }
624
625   /**
626    * Method unmarshal.
627    * 
628    * @param reader
629    * @throws org.exolab.castor.xml.MarshalException
630    *           if object is null or if any SAXException is thrown during
631    *           marshaling
632    * @throws org.exolab.castor.xml.ValidationException
633    *           if this object is an invalid instance according to the schema
634    * @return the unmarshaled jalview.binding.JSeq
635    */
636   public static jalview.binding.JSeq unmarshal(final java.io.Reader reader)
637           throws org.exolab.castor.xml.MarshalException,
638           org.exolab.castor.xml.ValidationException
639   {
640     return (jalview.binding.JSeq) Unmarshaller.unmarshal(
641             jalview.binding.JSeq.class, reader);
642   }
643
644   /**
645    * 
646    * 
647    * @throws org.exolab.castor.xml.ValidationException
648    *           if this object is an invalid instance according to the schema
649    */
650   public void validate() throws org.exolab.castor.xml.ValidationException
651   {
652     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
653     validator.validate(this);
654   }
655
656 }