14d98449ffb36b986b6a015f2bc844e8a71f5bd1
[jalview.git] / src / jalview / schemabinding / version2 / FeatureSettings.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3  * Copyright (C) 2014 The Jalview Authors
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
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.schemabinding.version2;
22
23 //---------------------------------/
24 //- Imported classes and packages -/
25 //---------------------------------/
26
27 import jalview.util.MessageManager;
28
29 import org.exolab.castor.xml.Marshaller;
30 import org.exolab.castor.xml.Unmarshaller;
31
32 /**
33  * Class FeatureSettings.
34  * 
35  * @version $Revision$ $Date$
36  */
37 public class FeatureSettings implements java.io.Serializable
38 {
39
40   // --------------------------/
41   // - Class/Member Variables -/
42   // --------------------------/
43
44   /**
45    * Field _settingList.
46    */
47   private java.util.Vector _settingList;
48
49   /**
50    * Field _groupList.
51    */
52   private java.util.Vector _groupList;
53
54   // ----------------/
55   // - Constructors -/
56   // ----------------/
57
58   public FeatureSettings()
59   {
60     super();
61     this._settingList = new java.util.Vector();
62     this._groupList = new java.util.Vector();
63   }
64
65   // -----------/
66   // - Methods -/
67   // -----------/
68
69   /**
70    * 
71    * 
72    * @param vGroup
73    * @throws java.lang.IndexOutOfBoundsException
74    *           if the index given is outside the bounds of the collection
75    */
76   public void addGroup(final jalview.schemabinding.version2.Group vGroup)
77           throws java.lang.IndexOutOfBoundsException
78   {
79     this._groupList.addElement(vGroup);
80   }
81
82   /**
83    * 
84    * 
85    * @param index
86    * @param vGroup
87    * @throws java.lang.IndexOutOfBoundsException
88    *           if the index given is outside the bounds of the collection
89    */
90   public void addGroup(final int index,
91           final jalview.schemabinding.version2.Group vGroup)
92           throws java.lang.IndexOutOfBoundsException
93   {
94     this._groupList.add(index, vGroup);
95   }
96
97   /**
98    * 
99    * 
100    * @param vSetting
101    * @throws java.lang.IndexOutOfBoundsException
102    *           if the index given is outside the bounds of the collection
103    */
104   public void addSetting(
105           final jalview.schemabinding.version2.Setting vSetting)
106           throws java.lang.IndexOutOfBoundsException
107   {
108     this._settingList.addElement(vSetting);
109   }
110
111   /**
112    * 
113    * 
114    * @param index
115    * @param vSetting
116    * @throws java.lang.IndexOutOfBoundsException
117    *           if the index given is outside the bounds of the collection
118    */
119   public void addSetting(final int index,
120           final jalview.schemabinding.version2.Setting vSetting)
121           throws java.lang.IndexOutOfBoundsException
122   {
123     this._settingList.add(index, vSetting);
124   }
125
126   /**
127    * Method enumerateGroup.
128    * 
129    * @return an Enumeration over all jalview.schemabinding.version2.Group
130    *         elements
131    */
132   public java.util.Enumeration enumerateGroup()
133   {
134     return this._groupList.elements();
135   }
136
137   /**
138    * Method enumerateSetting.
139    * 
140    * @return an Enumeration over all jalview.schemabinding.version2.Setting
141    *         elements
142    */
143   public java.util.Enumeration enumerateSetting()
144   {
145     return this._settingList.elements();
146   }
147
148   /**
149    * Method getGroup.
150    * 
151    * @param index
152    * @throws java.lang.IndexOutOfBoundsException
153    *           if the index given is outside the bounds of the collection
154    * @return the value of the jalview.schemabinding.version2.Group at the given
155    *         index
156    */
157   public jalview.schemabinding.version2.Group getGroup(final int index)
158           throws java.lang.IndexOutOfBoundsException
159   {
160     // check bounds for index
161     if (index < 0 || index >= this._groupList.size())
162     {
163         throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
164                           "getGroup",
165                           Integer.valueOf(index).toString(),
166                           Integer.valueOf((this._groupList.size() - 1)).toString()
167           })); 
168     }
169
170     return (jalview.schemabinding.version2.Group) _groupList.get(index);
171   }
172
173   /**
174    * Method getGroup.Returns the contents of the collection in an Array.
175    * <p>
176    * Note: Just in case the collection contents are changing in another thread,
177    * we pass a 0-length Array of the correct type into the API call. This way we
178    * <i>know</i> that the Array returned is of exactly the correct length.
179    * 
180    * @return this collection as an Array
181    */
182   public jalview.schemabinding.version2.Group[] getGroup()
183   {
184     jalview.schemabinding.version2.Group[] array = new jalview.schemabinding.version2.Group[0];
185     return (jalview.schemabinding.version2.Group[]) this._groupList
186             .toArray(array);
187   }
188
189   /**
190    * Method getGroupCount.
191    * 
192    * @return the size of this collection
193    */
194   public int getGroupCount()
195   {
196     return this._groupList.size();
197   }
198
199   /**
200    * Method getSetting.
201    * 
202    * @param index
203    * @throws java.lang.IndexOutOfBoundsException
204    *           if the index given is outside the bounds of the collection
205    * @return the value of the jalview.schemabinding.version2.Setting at the
206    *         given index
207    */
208   public jalview.schemabinding.version2.Setting getSetting(final int index)
209           throws java.lang.IndexOutOfBoundsException
210   {
211     // check bounds for index
212     if (index < 0 || index >= this._settingList.size())
213     {
214         throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
215                   "getSetting",
216                   Integer.valueOf(index).toString(),
217                   Integer.valueOf((this._settingList.size() - 1)).toString()
218         })); 
219     }
220
221     return (jalview.schemabinding.version2.Setting) _settingList.get(index);
222   }
223
224   /**
225    * Method getSetting.Returns the contents of the collection in an Array.
226    * <p>
227    * Note: Just in case the collection contents are changing in another thread,
228    * we pass a 0-length Array of the correct type into the API call. This way we
229    * <i>know</i> that the Array returned is of exactly the correct length.
230    * 
231    * @return this collection as an Array
232    */
233   public jalview.schemabinding.version2.Setting[] getSetting()
234   {
235     jalview.schemabinding.version2.Setting[] array = new jalview.schemabinding.version2.Setting[0];
236     return (jalview.schemabinding.version2.Setting[]) this._settingList
237             .toArray(array);
238   }
239
240   /**
241    * Method getSettingCount.
242    * 
243    * @return the size of this collection
244    */
245   public int getSettingCount()
246   {
247     return this._settingList.size();
248   }
249
250   /**
251    * Method isValid.
252    * 
253    * @return true if this object is valid according to the schema
254    */
255   public boolean isValid()
256   {
257     try
258     {
259       validate();
260     } catch (org.exolab.castor.xml.ValidationException vex)
261     {
262       return false;
263     }
264     return true;
265   }
266
267   /**
268    * 
269    * 
270    * @param out
271    * @throws org.exolab.castor.xml.MarshalException
272    *           if object is null or if any SAXException is thrown during
273    *           marshaling
274    * @throws org.exolab.castor.xml.ValidationException
275    *           if this object is an invalid instance according to the schema
276    */
277   public void marshal(final java.io.Writer out)
278           throws org.exolab.castor.xml.MarshalException,
279           org.exolab.castor.xml.ValidationException
280   {
281     Marshaller.marshal(this, out);
282   }
283
284   /**
285    * 
286    * 
287    * @param handler
288    * @throws java.io.IOException
289    *           if an IOException occurs during marshaling
290    * @throws org.exolab.castor.xml.ValidationException
291    *           if this object is an invalid instance according to the schema
292    * @throws org.exolab.castor.xml.MarshalException
293    *           if object is null or if any SAXException is thrown during
294    *           marshaling
295    */
296   public void marshal(final org.xml.sax.ContentHandler handler)
297           throws java.io.IOException,
298           org.exolab.castor.xml.MarshalException,
299           org.exolab.castor.xml.ValidationException
300   {
301     Marshaller.marshal(this, handler);
302   }
303
304   /**
305      */
306   public void removeAllGroup()
307   {
308     this._groupList.clear();
309   }
310
311   /**
312      */
313   public void removeAllSetting()
314   {
315     this._settingList.clear();
316   }
317
318   /**
319    * Method removeGroup.
320    * 
321    * @param vGroup
322    * @return true if the object was removed from the collection.
323    */
324   public boolean removeGroup(
325           final jalview.schemabinding.version2.Group vGroup)
326   {
327     boolean removed = _groupList.remove(vGroup);
328     return removed;
329   }
330
331   /**
332    * Method removeGroupAt.
333    * 
334    * @param index
335    * @return the element removed from the collection
336    */
337   public jalview.schemabinding.version2.Group removeGroupAt(final int index)
338   {
339     java.lang.Object obj = this._groupList.remove(index);
340     return (jalview.schemabinding.version2.Group) obj;
341   }
342
343   /**
344    * Method removeSetting.
345    * 
346    * @param vSetting
347    * @return true if the object was removed from the collection.
348    */
349   public boolean removeSetting(
350           final jalview.schemabinding.version2.Setting vSetting)
351   {
352     boolean removed = _settingList.remove(vSetting);
353     return removed;
354   }
355
356   /**
357    * Method removeSettingAt.
358    * 
359    * @param index
360    * @return the element removed from the collection
361    */
362   public jalview.schemabinding.version2.Setting removeSettingAt(
363           final int index)
364   {
365     java.lang.Object obj = this._settingList.remove(index);
366     return (jalview.schemabinding.version2.Setting) obj;
367   }
368
369   /**
370    * 
371    * 
372    * @param index
373    * @param vGroup
374    * @throws java.lang.IndexOutOfBoundsException
375    *           if the index given is outside the bounds of the collection
376    */
377   public void setGroup(final int index,
378           final jalview.schemabinding.version2.Group vGroup)
379           throws java.lang.IndexOutOfBoundsException
380   {
381     // check bounds for index
382     if (index < 0 || index >= this._groupList.size())
383     {
384         throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
385                           "setGroup",
386                           Integer.valueOf(index).toString(),
387                           Integer.valueOf((this._groupList.size() - 1)).toString()
388           })); 
389     }
390
391     this._groupList.set(index, vGroup);
392   }
393
394   /**
395    * 
396    * 
397    * @param vGroupArray
398    */
399   public void setGroup(
400           final jalview.schemabinding.version2.Group[] vGroupArray)
401   {
402     // -- copy array
403     _groupList.clear();
404
405     for (int i = 0; i < vGroupArray.length; i++)
406     {
407       this._groupList.add(vGroupArray[i]);
408     }
409   }
410
411   /**
412    * 
413    * 
414    * @param index
415    * @param vSetting
416    * @throws java.lang.IndexOutOfBoundsException
417    *           if the index given is outside the bounds of the collection
418    */
419   public void setSetting(final int index,
420           final jalview.schemabinding.version2.Setting vSetting)
421           throws java.lang.IndexOutOfBoundsException
422   {
423     // check bounds for index
424     if (index < 0 || index >= this._settingList.size())
425     {
426         throw new IndexOutOfBoundsException(MessageManager.formatMessage("exception.index_value_not_in_range", new String[]{
427                   "setSetting",
428                   Integer.valueOf(index).toString(),
429                   Integer.valueOf((this._settingList.size() - 1)).toString()
430         })); 
431     }
432
433     this._settingList.set(index, vSetting);
434   }
435
436   /**
437    * 
438    * 
439    * @param vSettingArray
440    */
441   public void setSetting(
442           final jalview.schemabinding.version2.Setting[] vSettingArray)
443   {
444     // -- copy array
445     _settingList.clear();
446
447     for (int i = 0; i < vSettingArray.length; i++)
448     {
449       this._settingList.add(vSettingArray[i]);
450     }
451   }
452
453   /**
454    * Method unmarshal.
455    * 
456    * @param reader
457    * @throws org.exolab.castor.xml.MarshalException
458    *           if object is null or if any SAXException is thrown during
459    *           marshaling
460    * @throws org.exolab.castor.xml.ValidationException
461    *           if this object is an invalid instance according to the schema
462    * @return the unmarshaled jalview.schemabinding.version2.FeatureSettings
463    */
464   public static jalview.schemabinding.version2.FeatureSettings unmarshal(
465           final java.io.Reader reader)
466           throws org.exolab.castor.xml.MarshalException,
467           org.exolab.castor.xml.ValidationException
468   {
469     return (jalview.schemabinding.version2.FeatureSettings) Unmarshaller
470             .unmarshal(
471                     jalview.schemabinding.version2.FeatureSettings.class,
472                     reader);
473   }
474
475   /**
476    * 
477    * 
478    * @throws org.exolab.castor.xml.ValidationException
479    *           if this object is an invalid instance according to the schema
480    */
481   public void validate() throws org.exolab.castor.xml.ValidationException
482   {
483     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
484     validator.validate(this);
485   }
486
487 }