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