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