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