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