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