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