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