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