merge from 2_4_Release branch
[jalview.git] / src / jalview / binding / JSeq.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3  * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  * 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * 
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
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
409    *                 schema
410    */
411   public void marshal(final java.io.Writer out)
412           throws org.exolab.castor.xml.MarshalException,
413           org.exolab.castor.xml.ValidationException
414   {
415     Marshaller.marshal(this, out);
416   }
417
418   /**
419    * 
420    * 
421    * @param handler
422    * @throws java.io.IOException
423    *                 if an IOException occurs during marshaling
424    * @throws org.exolab.castor.xml.ValidationException
425    *                 if this object is an invalid instance according to the
426    *                 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
636    *                 schema
637    * @return the unmarshaled jalview.binding.JSeq
638    */
639   public static jalview.binding.JSeq unmarshal(final java.io.Reader reader)
640           throws org.exolab.castor.xml.MarshalException,
641           org.exolab.castor.xml.ValidationException
642   {
643     return (jalview.binding.JSeq) Unmarshaller.unmarshal(
644             jalview.binding.JSeq.class, reader);
645   }
646
647   /**
648    * 
649    * 
650    * @throws org.exolab.castor.xml.ValidationException
651    *                 if this object is an invalid instance according to the
652    *                 schema
653    */
654   public void validate() throws org.exolab.castor.xml.ValidationException
655   {
656     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
657     validator.validate(this);
658   }
659
660 }