369ec7ac9a1d7ee2e489e52e67b868d7e770f005
[jalview.git] / src / jalview / schemabinding / version2 / PdbentryItem.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
3  * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
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  */
18 package jalview.schemabinding.version2;
19
20 /**
21  * Class PdbentryItem.
22  * 
23  * @version $Revision$ $Date$
24  */
25 public class PdbentryItem implements java.io.Serializable
26 {
27
28   // --------------------------/
29   // - Class/Member Variables -/
30   // --------------------------/
31
32   /**
33    * Field _propertyList.
34    */
35   private java.util.Vector _propertyList;
36
37   // ----------------/
38   // - Constructors -/
39   // ----------------/
40
41   public PdbentryItem()
42   {
43     super();
44     this._propertyList = new java.util.Vector();
45   }
46
47   // -----------/
48   // - Methods -/
49   // -----------/
50
51   /**
52    * 
53    * 
54    * @param vProperty
55    * @throws java.lang.IndexOutOfBoundsException
56    *           if the index given is outside the bounds of the collection
57    */
58   public void addProperty(
59           final jalview.schemabinding.version2.Property vProperty)
60           throws java.lang.IndexOutOfBoundsException
61   {
62     this._propertyList.addElement(vProperty);
63   }
64
65   /**
66    * 
67    * 
68    * @param index
69    * @param vProperty
70    * @throws java.lang.IndexOutOfBoundsException
71    *           if the index given is outside the bounds of the collection
72    */
73   public void addProperty(final int index,
74           final jalview.schemabinding.version2.Property vProperty)
75           throws java.lang.IndexOutOfBoundsException
76   {
77     this._propertyList.add(index, vProperty);
78   }
79
80   /**
81    * Method enumerateProperty.
82    * 
83    * @return an Enumeration over all jalview.schemabinding.version2.Property
84    *         elements
85    */
86   public java.util.Enumeration enumerateProperty()
87   {
88     return this._propertyList.elements();
89   }
90
91   /**
92    * Method getProperty.
93    * 
94    * @param index
95    * @throws java.lang.IndexOutOfBoundsException
96    *           if the index given is outside the bounds of the collection
97    * @return the value of the jalview.schemabinding.version2.Property at the
98    *         given index
99    */
100   public jalview.schemabinding.version2.Property getProperty(final int index)
101           throws java.lang.IndexOutOfBoundsException
102   {
103     // check bounds for index
104     if (index < 0 || index >= this._propertyList.size())
105     {
106       throw new IndexOutOfBoundsException("getProperty: Index value '"
107               + index + "' not in range [0.."
108               + (this._propertyList.size() - 1) + "]");
109     }
110
111     return (jalview.schemabinding.version2.Property) _propertyList
112             .get(index);
113   }
114
115   /**
116    * Method getProperty.Returns the contents of the collection in an Array.
117    * <p>
118    * Note: Just in case the collection contents are changing in another thread,
119    * we pass a 0-length Array of the correct type into the API call. This way we
120    * <i>know</i> that the Array returned is of exactly the correct length.
121    * 
122    * @return this collection as an Array
123    */
124   public jalview.schemabinding.version2.Property[] getProperty()
125   {
126     jalview.schemabinding.version2.Property[] array = new jalview.schemabinding.version2.Property[0];
127     return (jalview.schemabinding.version2.Property[]) this._propertyList
128             .toArray(array);
129   }
130
131   /**
132    * Method getPropertyCount.
133    * 
134    * @return the size of this collection
135    */
136   public int getPropertyCount()
137   {
138     return this._propertyList.size();
139   }
140
141   /**
142      */
143   public void removeAllProperty()
144   {
145     this._propertyList.clear();
146   }
147
148   /**
149    * Method removeProperty.
150    * 
151    * @param vProperty
152    * @return true if the object was removed from the collection.
153    */
154   public boolean removeProperty(
155           final jalview.schemabinding.version2.Property vProperty)
156   {
157     boolean removed = _propertyList.remove(vProperty);
158     return removed;
159   }
160
161   /**
162    * Method removePropertyAt.
163    * 
164    * @param index
165    * @return the element removed from the collection
166    */
167   public jalview.schemabinding.version2.Property removePropertyAt(
168           final int index)
169   {
170     java.lang.Object obj = this._propertyList.remove(index);
171     return (jalview.schemabinding.version2.Property) obj;
172   }
173
174   /**
175    * 
176    * 
177    * @param index
178    * @param vProperty
179    * @throws java.lang.IndexOutOfBoundsException
180    *           if the index given is outside the bounds of the collection
181    */
182   public void setProperty(final int index,
183           final jalview.schemabinding.version2.Property vProperty)
184           throws java.lang.IndexOutOfBoundsException
185   {
186     // check bounds for index
187     if (index < 0 || index >= this._propertyList.size())
188     {
189       throw new IndexOutOfBoundsException("setProperty: Index value '"
190               + index + "' not in range [0.."
191               + (this._propertyList.size() - 1) + "]");
192     }
193
194     this._propertyList.set(index, vProperty);
195   }
196
197   /**
198    * 
199    * 
200    * @param vPropertyArray
201    */
202   public void setProperty(
203           final jalview.schemabinding.version2.Property[] vPropertyArray)
204   {
205     // -- copy array
206     _propertyList.clear();
207
208     for (int i = 0; i < vPropertyArray.length; i++)
209     {
210       this._propertyList.add(vPropertyArray[i]);
211     }
212   }
213
214 }