733edbaee342ad673fc895aafa9d3465e3b1cee4
[jalview.git] / src / jalview / binding / 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.binding;
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(final jalview.binding.Property vProperty)
59           throws java.lang.IndexOutOfBoundsException
60   {
61     this._propertyList.addElement(vProperty);
62   }
63
64   /**
65    * 
66    * 
67    * @param index
68    * @param vProperty
69    * @throws java.lang.IndexOutOfBoundsException
70    *           if the index given is outside the bounds of the collection
71    */
72   public void addProperty(final int index,
73           final jalview.binding.Property vProperty)
74           throws java.lang.IndexOutOfBoundsException
75   {
76     this._propertyList.add(index, vProperty);
77   }
78
79   /**
80    * Method enumerateProperty.
81    * 
82    * @return an Enumeration over all jalview.binding.Property elements
83    */
84   public java.util.Enumeration enumerateProperty()
85   {
86     return this._propertyList.elements();
87   }
88
89   /**
90    * Method getProperty.
91    * 
92    * @param index
93    * @throws java.lang.IndexOutOfBoundsException
94    *           if the index given is outside the bounds of the collection
95    * @return the value of the jalview.binding.Property at the given index
96    */
97   public jalview.binding.Property getProperty(final int index)
98           throws java.lang.IndexOutOfBoundsException
99   {
100     // check bounds for index
101     if (index < 0 || index >= this._propertyList.size())
102     {
103       throw new IndexOutOfBoundsException("getProperty: Index value '"
104               + index + "' not in range [0.."
105               + (this._propertyList.size() - 1) + "]");
106     }
107
108     return (jalview.binding.Property) _propertyList.get(index);
109   }
110
111   /**
112    * Method getProperty.Returns the contents of the collection in an Array.
113    * <p>
114    * Note: Just in case the collection contents are changing in another thread,
115    * we pass a 0-length Array of the correct type into the API call. This way we
116    * <i>know</i> that the Array returned is of exactly the correct length.
117    * 
118    * @return this collection as an Array
119    */
120   public jalview.binding.Property[] getProperty()
121   {
122     jalview.binding.Property[] array = new jalview.binding.Property[0];
123     return (jalview.binding.Property[]) this._propertyList.toArray(array);
124   }
125
126   /**
127    * Method getPropertyCount.
128    * 
129    * @return the size of this collection
130    */
131   public int getPropertyCount()
132   {
133     return this._propertyList.size();
134   }
135
136   /**
137      */
138   public void removeAllProperty()
139   {
140     this._propertyList.clear();
141   }
142
143   /**
144    * Method removeProperty.
145    * 
146    * @param vProperty
147    * @return true if the object was removed from the collection.
148    */
149   public boolean removeProperty(final jalview.binding.Property vProperty)
150   {
151     boolean removed = _propertyList.remove(vProperty);
152     return removed;
153   }
154
155   /**
156    * Method removePropertyAt.
157    * 
158    * @param index
159    * @return the element removed from the collection
160    */
161   public jalview.binding.Property removePropertyAt(final int index)
162   {
163     java.lang.Object obj = this._propertyList.remove(index);
164     return (jalview.binding.Property) obj;
165   }
166
167   /**
168    * 
169    * 
170    * @param index
171    * @param vProperty
172    * @throws java.lang.IndexOutOfBoundsException
173    *           if the index given is outside the bounds of the collection
174    */
175   public void setProperty(final int index,
176           final jalview.binding.Property vProperty)
177           throws java.lang.IndexOutOfBoundsException
178   {
179     // check bounds for index
180     if (index < 0 || index >= this._propertyList.size())
181     {
182       throw new IndexOutOfBoundsException("setProperty: Index value '"
183               + index + "' not in range [0.."
184               + (this._propertyList.size() - 1) + "]");
185     }
186
187     this._propertyList.set(index, vProperty);
188   }
189
190   /**
191    * 
192    * 
193    * @param vPropertyArray
194    */
195   public void setProperty(final jalview.binding.Property[] vPropertyArray)
196   {
197     // -- copy array
198     _propertyList.clear();
199
200     for (int i = 0; i < vPropertyArray.length; i++)
201     {
202       this._propertyList.add(vPropertyArray[i]);
203     }
204   }
205
206 }