7a490c0e1a012b7a1fa51034e0ea9829ba9c039a
[jalview.git] / src / jalview / schemabinding / version2 / MapListType.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.schemabinding.version2;
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  * developed after mapRangeType from
29  * http://www.vamsas.ac.uk/schemas/1.0/vamsasTypes
30  * 
31  * This effectively represents a java.util.MapList object
32  * 
33  * 
34  * @version $Revision$ $Date$
35  */
36 public class MapListType implements java.io.Serializable
37 {
38
39   // --------------------------/
40   // - Class/Member Variables -/
41   // --------------------------/
42
43   /**
44    * number of dictionary symbol widths involved in each mapped position on this
45    * sequence (for example, 3 for a dna sequence exon region that is being
46    * mapped to a protein sequence). This is optional, since the unit can be
47    * usually be inferred from the dictionary type of each sequence involved in
48    * the mapping.
49    */
50   private long _mapFromUnit;
51
52   /**
53    * keeps track of state for field: _mapFromUnit
54    */
55   private boolean _has_mapFromUnit;
56
57   /**
58    * number of dictionary symbol widths involved in each mapped position on this
59    * sequence (for example, 3 for a dna sequence exon region that is being
60    * mapped to a protein sequence). This is optional, since the unit can be
61    * usually be inferred from the dictionary type of each sequence involved in
62    * the mapping.
63    */
64   private long _mapToUnit;
65
66   /**
67    * keeps track of state for field: _mapToUnit
68    */
69   private boolean _has_mapToUnit;
70
71   /**
72    * a region from start to end inclusive
73    */
74   private java.util.Vector _mapListFromList;
75
76   /**
77    * a region from start to end inclusive
78    */
79   private java.util.Vector _mapListToList;
80
81   // ----------------/
82   // - Constructors -/
83   // ----------------/
84
85   public MapListType()
86   {
87     super();
88     this._mapListFromList = new java.util.Vector();
89     this._mapListToList = new java.util.Vector();
90   }
91
92   // -----------/
93   // - Methods -/
94   // -----------/
95
96   /**
97    * 
98    * 
99    * @param vMapListFrom
100    * @throws java.lang.IndexOutOfBoundsException
101    *           if the index given is outside the bounds of the collection
102    */
103   public void addMapListFrom(
104           final jalview.schemabinding.version2.MapListFrom vMapListFrom)
105           throws java.lang.IndexOutOfBoundsException
106   {
107     this._mapListFromList.addElement(vMapListFrom);
108   }
109
110   /**
111    * 
112    * 
113    * @param index
114    * @param vMapListFrom
115    * @throws java.lang.IndexOutOfBoundsException
116    *           if the index given is outside the bounds of the collection
117    */
118   public void addMapListFrom(final int index,
119           final jalview.schemabinding.version2.MapListFrom vMapListFrom)
120           throws java.lang.IndexOutOfBoundsException
121   {
122     this._mapListFromList.add(index, vMapListFrom);
123   }
124
125   /**
126    * 
127    * 
128    * @param vMapListTo
129    * @throws java.lang.IndexOutOfBoundsException
130    *           if the index given is outside the bounds of the collection
131    */
132   public void addMapListTo(
133           final jalview.schemabinding.version2.MapListTo vMapListTo)
134           throws java.lang.IndexOutOfBoundsException
135   {
136     this._mapListToList.addElement(vMapListTo);
137   }
138
139   /**
140    * 
141    * 
142    * @param index
143    * @param vMapListTo
144    * @throws java.lang.IndexOutOfBoundsException
145    *           if the index given is outside the bounds of the collection
146    */
147   public void addMapListTo(final int index,
148           final jalview.schemabinding.version2.MapListTo vMapListTo)
149           throws java.lang.IndexOutOfBoundsException
150   {
151     this._mapListToList.add(index, vMapListTo);
152   }
153
154   /**
155      */
156   public void deleteMapFromUnit()
157   {
158     this._has_mapFromUnit = false;
159   }
160
161   /**
162      */
163   public void deleteMapToUnit()
164   {
165     this._has_mapToUnit = false;
166   }
167
168   /**
169    * Method enumerateMapListFrom.
170    * 
171    * @return an Enumeration over all jalview.schemabinding.version2.MapListFrom
172    *         elements
173    */
174   public java.util.Enumeration enumerateMapListFrom()
175   {
176     return this._mapListFromList.elements();
177   }
178
179   /**
180    * Method enumerateMapListTo.
181    * 
182    * @return an Enumeration over all jalview.schemabinding.version2.MapListTo
183    *         elements
184    */
185   public java.util.Enumeration enumerateMapListTo()
186   {
187     return this._mapListToList.elements();
188   }
189
190   /**
191    * Returns the value of field 'mapFromUnit'. The field 'mapFromUnit' has the
192    * following description: number of dictionary symbol widths involved in each
193    * mapped position on this sequence (for example, 3 for a dna sequence exon
194    * region that is being mapped to a protein sequence). This is optional, since
195    * the unit can be usually be inferred from the dictionary type of each
196    * sequence involved in the mapping.
197    * 
198    * @return the value of field 'MapFromUnit'.
199    */
200   public long getMapFromUnit()
201   {
202     return this._mapFromUnit;
203   }
204
205   /**
206    * Method getMapListFrom.
207    * 
208    * @param index
209    * @throws java.lang.IndexOutOfBoundsException
210    *           if the index given is outside the bounds of the collection
211    * @return the value of the jalview.schemabinding.version2.MapListFrom at the
212    *         given index
213    */
214   public jalview.schemabinding.version2.MapListFrom getMapListFrom(
215           final int index) throws java.lang.IndexOutOfBoundsException
216   {
217     // check bounds for index
218     if (index < 0 || index >= this._mapListFromList.size())
219     {
220       throw new IndexOutOfBoundsException("getMapListFrom: Index value '"
221               + index + "' not in range [0.."
222               + (this._mapListFromList.size() - 1) + "]");
223     }
224
225     return (jalview.schemabinding.version2.MapListFrom) _mapListFromList
226             .get(index);
227   }
228
229   /**
230    * Method getMapListFrom.Returns the contents of the collection in an Array.
231    * <p>
232    * Note: Just in case the collection contents are changing in another thread,
233    * we pass a 0-length Array of the correct type into the API call. This way we
234    * <i>know</i> that the Array returned is of exactly the correct length.
235    * 
236    * @return this collection as an Array
237    */
238   public jalview.schemabinding.version2.MapListFrom[] getMapListFrom()
239   {
240     jalview.schemabinding.version2.MapListFrom[] array = new jalview.schemabinding.version2.MapListFrom[0];
241     return (jalview.schemabinding.version2.MapListFrom[]) this._mapListFromList
242             .toArray(array);
243   }
244
245   /**
246    * Method getMapListFromCount.
247    * 
248    * @return the size of this collection
249    */
250   public int getMapListFromCount()
251   {
252     return this._mapListFromList.size();
253   }
254
255   /**
256    * Method getMapListTo.
257    * 
258    * @param index
259    * @throws java.lang.IndexOutOfBoundsException
260    *           if the index given is outside the bounds of the collection
261    * @return the value of the jalview.schemabinding.version2.MapListTo at the
262    *         given index
263    */
264   public jalview.schemabinding.version2.MapListTo getMapListTo(
265           final int index) throws java.lang.IndexOutOfBoundsException
266   {
267     // check bounds for index
268     if (index < 0 || index >= this._mapListToList.size())
269     {
270       throw new IndexOutOfBoundsException("getMapListTo: Index value '"
271               + index + "' not in range [0.."
272               + (this._mapListToList.size() - 1) + "]");
273     }
274
275     return (jalview.schemabinding.version2.MapListTo) _mapListToList
276             .get(index);
277   }
278
279   /**
280    * Method getMapListTo.Returns the contents of the collection in an Array.
281    * <p>
282    * Note: Just in case the collection contents are changing in another thread,
283    * we pass a 0-length Array of the correct type into the API call. This way we
284    * <i>know</i> that the Array returned is of exactly the correct length.
285    * 
286    * @return this collection as an Array
287    */
288   public jalview.schemabinding.version2.MapListTo[] getMapListTo()
289   {
290     jalview.schemabinding.version2.MapListTo[] array = new jalview.schemabinding.version2.MapListTo[0];
291     return (jalview.schemabinding.version2.MapListTo[]) this._mapListToList
292             .toArray(array);
293   }
294
295   /**
296    * Method getMapListToCount.
297    * 
298    * @return the size of this collection
299    */
300   public int getMapListToCount()
301   {
302     return this._mapListToList.size();
303   }
304
305   /**
306    * Returns the value of field 'mapToUnit'. The field 'mapToUnit' has the
307    * following description: number of dictionary symbol widths involved in each
308    * mapped position on this sequence (for example, 3 for a dna sequence exon
309    * region that is being mapped to a protein sequence). This is optional, since
310    * the unit can be usually be inferred from the dictionary type of each
311    * sequence involved in the mapping.
312    * 
313    * @return the value of field 'MapToUnit'.
314    */
315   public long getMapToUnit()
316   {
317     return this._mapToUnit;
318   }
319
320   /**
321    * Method hasMapFromUnit.
322    * 
323    * @return true if at least one MapFromUnit has been added
324    */
325   public boolean hasMapFromUnit()
326   {
327     return this._has_mapFromUnit;
328   }
329
330   /**
331    * Method hasMapToUnit.
332    * 
333    * @return true if at least one MapToUnit has been added
334    */
335   public boolean hasMapToUnit()
336   {
337     return this._has_mapToUnit;
338   }
339
340   /**
341    * Method isValid.
342    * 
343    * @return true if this object is valid according to the schema
344    */
345   public boolean isValid()
346   {
347     try
348     {
349       validate();
350     } catch (org.exolab.castor.xml.ValidationException vex)
351     {
352       return false;
353     }
354     return true;
355   }
356
357   /**
358    * 
359    * 
360    * @param out
361    * @throws org.exolab.castor.xml.MarshalException
362    *           if object is null or if any SAXException is thrown during
363    *           marshaling
364    * @throws org.exolab.castor.xml.ValidationException
365    *           if this object is an invalid instance according to the schema
366    */
367   public void marshal(final java.io.Writer out)
368           throws org.exolab.castor.xml.MarshalException,
369           org.exolab.castor.xml.ValidationException
370   {
371     Marshaller.marshal(this, out);
372   }
373
374   /**
375    * 
376    * 
377    * @param handler
378    * @throws java.io.IOException
379    *           if an IOException occurs during marshaling
380    * @throws org.exolab.castor.xml.ValidationException
381    *           if this object is an invalid instance according to the schema
382    * @throws org.exolab.castor.xml.MarshalException
383    *           if object is null or if any SAXException is thrown during
384    *           marshaling
385    */
386   public void marshal(final org.xml.sax.ContentHandler handler)
387           throws java.io.IOException,
388           org.exolab.castor.xml.MarshalException,
389           org.exolab.castor.xml.ValidationException
390   {
391     Marshaller.marshal(this, handler);
392   }
393
394   /**
395      */
396   public void removeAllMapListFrom()
397   {
398     this._mapListFromList.clear();
399   }
400
401   /**
402      */
403   public void removeAllMapListTo()
404   {
405     this._mapListToList.clear();
406   }
407
408   /**
409    * Method removeMapListFrom.
410    * 
411    * @param vMapListFrom
412    * @return true if the object was removed from the collection.
413    */
414   public boolean removeMapListFrom(
415           final jalview.schemabinding.version2.MapListFrom vMapListFrom)
416   {
417     boolean removed = _mapListFromList.remove(vMapListFrom);
418     return removed;
419   }
420
421   /**
422    * Method removeMapListFromAt.
423    * 
424    * @param index
425    * @return the element removed from the collection
426    */
427   public jalview.schemabinding.version2.MapListFrom removeMapListFromAt(
428           final int index)
429   {
430     java.lang.Object obj = this._mapListFromList.remove(index);
431     return (jalview.schemabinding.version2.MapListFrom) obj;
432   }
433
434   /**
435    * Method removeMapListTo.
436    * 
437    * @param vMapListTo
438    * @return true if the object was removed from the collection.
439    */
440   public boolean removeMapListTo(
441           final jalview.schemabinding.version2.MapListTo vMapListTo)
442   {
443     boolean removed = _mapListToList.remove(vMapListTo);
444     return removed;
445   }
446
447   /**
448    * Method removeMapListToAt.
449    * 
450    * @param index
451    * @return the element removed from the collection
452    */
453   public jalview.schemabinding.version2.MapListTo removeMapListToAt(
454           final int index)
455   {
456     java.lang.Object obj = this._mapListToList.remove(index);
457     return (jalview.schemabinding.version2.MapListTo) obj;
458   }
459
460   /**
461    * Sets the value of field 'mapFromUnit'. The field 'mapFromUnit' has the
462    * following description: number of dictionary symbol widths involved in each
463    * mapped position on this sequence (for example, 3 for a dna sequence exon
464    * region that is being mapped to a protein sequence). This is optional, since
465    * the unit can be usually be inferred from the dictionary type of each
466    * sequence involved in the mapping.
467    * 
468    * @param mapFromUnit
469    *          the value of field 'mapFromUnit'.
470    */
471   public void setMapFromUnit(final long mapFromUnit)
472   {
473     this._mapFromUnit = mapFromUnit;
474     this._has_mapFromUnit = true;
475   }
476
477   /**
478    * 
479    * 
480    * @param index
481    * @param vMapListFrom
482    * @throws java.lang.IndexOutOfBoundsException
483    *           if the index given is outside the bounds of the collection
484    */
485   public void setMapListFrom(final int index,
486           final jalview.schemabinding.version2.MapListFrom vMapListFrom)
487           throws java.lang.IndexOutOfBoundsException
488   {
489     // check bounds for index
490     if (index < 0 || index >= this._mapListFromList.size())
491     {
492       throw new IndexOutOfBoundsException("setMapListFrom: Index value '"
493               + index + "' not in range [0.."
494               + (this._mapListFromList.size() - 1) + "]");
495     }
496
497     this._mapListFromList.set(index, vMapListFrom);
498   }
499
500   /**
501    * 
502    * 
503    * @param vMapListFromArray
504    */
505   public void setMapListFrom(
506           final jalview.schemabinding.version2.MapListFrom[] vMapListFromArray)
507   {
508     // -- copy array
509     _mapListFromList.clear();
510
511     for (int i = 0; i < vMapListFromArray.length; i++)
512     {
513       this._mapListFromList.add(vMapListFromArray[i]);
514     }
515   }
516
517   /**
518    * 
519    * 
520    * @param index
521    * @param vMapListTo
522    * @throws java.lang.IndexOutOfBoundsException
523    *           if the index given is outside the bounds of the collection
524    */
525   public void setMapListTo(final int index,
526           final jalview.schemabinding.version2.MapListTo vMapListTo)
527           throws java.lang.IndexOutOfBoundsException
528   {
529     // check bounds for index
530     if (index < 0 || index >= this._mapListToList.size())
531     {
532       throw new IndexOutOfBoundsException("setMapListTo: Index value '"
533               + index + "' not in range [0.."
534               + (this._mapListToList.size() - 1) + "]");
535     }
536
537     this._mapListToList.set(index, vMapListTo);
538   }
539
540   /**
541    * 
542    * 
543    * @param vMapListToArray
544    */
545   public void setMapListTo(
546           final jalview.schemabinding.version2.MapListTo[] vMapListToArray)
547   {
548     // -- copy array
549     _mapListToList.clear();
550
551     for (int i = 0; i < vMapListToArray.length; i++)
552     {
553       this._mapListToList.add(vMapListToArray[i]);
554     }
555   }
556
557   /**
558    * Sets the value of field 'mapToUnit'. The field 'mapToUnit' has the
559    * following description: number of dictionary symbol widths involved in each
560    * mapped position on this sequence (for example, 3 for a dna sequence exon
561    * region that is being mapped to a protein sequence). This is optional, since
562    * the unit can be usually be inferred from the dictionary type of each
563    * sequence involved in the mapping.
564    * 
565    * @param mapToUnit
566    *          the value of field 'mapToUnit'.
567    */
568   public void setMapToUnit(final long mapToUnit)
569   {
570     this._mapToUnit = mapToUnit;
571     this._has_mapToUnit = true;
572   }
573
574   /**
575    * Method unmarshal.
576    * 
577    * @param reader
578    * @throws org.exolab.castor.xml.MarshalException
579    *           if object is null or if any SAXException is thrown during
580    *           marshaling
581    * @throws org.exolab.castor.xml.ValidationException
582    *           if this object is an invalid instance according to the schema
583    * @return the unmarshaled jalview.schemabinding.version2.MapListType
584    */
585   public static jalview.schemabinding.version2.MapListType unmarshal(
586           final java.io.Reader reader)
587           throws org.exolab.castor.xml.MarshalException,
588           org.exolab.castor.xml.ValidationException
589   {
590     return (jalview.schemabinding.version2.MapListType) Unmarshaller
591             .unmarshal(jalview.schemabinding.version2.MapListType.class,
592                     reader);
593   }
594
595   /**
596    * 
597    * 
598    * @throws org.exolab.castor.xml.ValidationException
599    *           if this object is an invalid instance according to the schema
600    */
601   public void validate() throws org.exolab.castor.xml.ValidationException
602   {
603     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
604     validator.validate(this);
605   }
606
607 }