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