2 * This file is part of the Vamsas Client version 0.1.
\r
3 * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite,
\r
4 * Andrew Waterhouse and Dominik Lindner.
\r
6 * Earlier versions have also been incorporated into Jalview version 2.4
\r
7 * since 2008, and TOPALi version 2 since 2007.
\r
9 * The Vamsas Client is free software: you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation, either version 3 of the License, or
\r
12 * (at your option) any later version.
\r
14 * The Vamsas Client is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public License
\r
20 * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.
\r
22 package uk.ac.vamsas.objects.core;
\r
24 //---------------------------------/
\r
25 //- Imported classes and packages -/
\r
26 //---------------------------------/
\r
28 import org.exolab.castor.xml.Marshaller;
\r
29 import org.exolab.castor.xml.Unmarshaller;
\r
34 * @version $Revision$ $Date$
\r
36 public class Input extends uk.ac.vamsas.objects.core.RangeType implements
\r
37 java.io.Serializable {
\r
39 // --------------------------/
\r
40 // - Class/Member Variables -/
\r
41 // --------------------------/
\r
46 private java.lang.String _name;
\r
49 * Reference Frame for rangeType specfication
\r
52 private java.util.Vector _objRef;
\r
54 // ----------------/
\r
55 // - Constructors -/
\r
56 // ----------------/
\r
60 this._objRef = new java.util.Vector();
\r
71 * @throws java.lang.IndexOutOfBoundsException
\r
72 * if the index given is outside the bounds of the collection
\r
74 public void addObjRef(final java.lang.Object vObjRef)
\r
75 throws java.lang.IndexOutOfBoundsException {
\r
76 this._objRef.addElement(vObjRef);
\r
84 * @throws java.lang.IndexOutOfBoundsException
\r
85 * if the index given is outside the bounds of the collection
\r
87 public void addObjRef(final int index, final java.lang.Object vObjRef)
\r
88 throws java.lang.IndexOutOfBoundsException {
\r
89 this._objRef.add(index, vObjRef);
\r
93 * Method enumerateObjRef.
\r
95 * @return an Enumeration over all java.lang.Object elements
\r
97 public java.util.Enumeration enumerateObjRef() {
\r
98 return this._objRef.elements();
\r
102 * Overrides the java.lang.Object.equals method.
\r
105 * @return true if the objects are equal.
\r
107 public boolean equals(final java.lang.Object obj) {
\r
111 if (super.equals(obj) == false)
\r
114 if (obj instanceof Input) {
\r
116 Input temp = (Input) obj;
\r
119 if (this._name != null) {
\r
120 if (temp._name == null)
\r
122 if (this._name != temp._name) {
\r
123 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._name);
\r
124 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._name);
\r
125 if (thcycle != tmcycle) {
\r
127 org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
\r
131 org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
\r
137 if (!this._name.equals(temp._name)) {
\r
138 org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
\r
139 org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
\r
142 org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
\r
143 org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
\r
146 } else if (temp._name != null)
\r
148 if (this._objRef != null) {
\r
149 if (temp._objRef == null)
\r
151 if (this._objRef != temp._objRef) {
\r
152 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._objRef);
\r
153 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._objRef);
\r
154 if (thcycle != tmcycle) {
\r
156 org.castor.util.CycleBreaker.releaseCycleHandle(this._objRef);
\r
160 org.castor.util.CycleBreaker.releaseCycleHandle(temp._objRef);
\r
166 if (!this._objRef.equals(temp._objRef)) {
\r
167 org.castor.util.CycleBreaker.releaseCycleHandle(this._objRef);
\r
168 org.castor.util.CycleBreaker.releaseCycleHandle(temp._objRef);
\r
171 org.castor.util.CycleBreaker.releaseCycleHandle(this._objRef);
\r
172 org.castor.util.CycleBreaker.releaseCycleHandle(temp._objRef);
\r
175 } else if (temp._objRef != null)
\r
183 * Returns the value of field 'name'.
\r
185 * @return the value of field 'Name'.
\r
187 public java.lang.String getName() {
\r
192 * Method getObjRef.
\r
195 * @throws java.lang.IndexOutOfBoundsException
\r
196 * if the index given is outside the bounds of the collection
\r
197 * @return the value of the java.lang.Object at the given index
\r
199 public java.lang.Object getObjRef(final int index)
\r
200 throws java.lang.IndexOutOfBoundsException {
\r
201 // check bounds for index
\r
202 if (index < 0 || index >= this._objRef.size()) {
\r
203 throw new IndexOutOfBoundsException("getObjRef: Index value '" + index
\r
204 + "' not in range [0.." + (this._objRef.size() - 1) + "]");
\r
207 return _objRef.get(index);
\r
211 * Method getObjRef.Returns the contents of the collection in an Array.
\r
213 * Note: Just in case the collection contents are changing in another thread,
\r
214 * we pass a 0-length Array of the correct type into the API call. This way we
\r
215 * <i>know</i> that the Array returned is of exactly the correct length.
\r
217 * @return this collection as an Array
\r
219 public java.lang.Object[] getObjRef() {
\r
220 java.lang.Object[] array = new java.lang.Object[0];
\r
221 return (java.lang.Object[]) this._objRef.toArray(array);
\r
225 * Method getObjRefAsReference.Returns a reference to '_objRef'. No type
\r
226 * checking is performed on any modifications to the Vector.
\r
228 * @return a reference to the Vector backing this class
\r
230 public java.util.Vector getObjRefAsReference() {
\r
231 return this._objRef;
\r
235 * Method getObjRefCount.
\r
237 * @return the size of this collection
\r
239 public int getObjRefCount() {
\r
240 return this._objRef.size();
\r
244 * Overrides the java.lang.Object.hashCode method.
\r
246 * The following steps came from <b>Effective Java Programming Language
\r
247 * Guide</b> by Joshua Bloch, Chapter 3
\r
249 * @return a hash code value for the object.
\r
251 public int hashCode() {
\r
252 int result = super.hashCode();
\r
255 if (_name != null && !org.castor.util.CycleBreaker.startingToCycle(_name)) {
\r
256 result = 37 * result + _name.hashCode();
\r
257 org.castor.util.CycleBreaker.releaseCycleHandle(_name);
\r
259 if (_objRef != null
\r
260 && !org.castor.util.CycleBreaker.startingToCycle(_objRef)) {
\r
261 result = 37 * result + _objRef.hashCode();
\r
262 org.castor.util.CycleBreaker.releaseCycleHandle(_objRef);
\r
271 * @return true if this object is valid according to the schema
\r
273 public boolean isValid() {
\r
276 } catch (org.exolab.castor.xml.ValidationException vex) {
\r
286 * @throws org.exolab.castor.xml.MarshalException
\r
287 * if object is null or if any SAXException is thrown during
\r
289 * @throws org.exolab.castor.xml.ValidationException
\r
290 * if this object is an invalid instance according to the schema
\r
292 public void marshal(final java.io.Writer out)
\r
293 throws org.exolab.castor.xml.MarshalException,
\r
294 org.exolab.castor.xml.ValidationException {
\r
295 Marshaller.marshal(this, out);
\r
302 * @throws java.io.IOException
\r
303 * if an IOException occurs during marshaling
\r
304 * @throws org.exolab.castor.xml.ValidationException
\r
305 * if this object is an invalid instance according to the schema
\r
306 * @throws org.exolab.castor.xml.MarshalException
\r
307 * if object is null or if any SAXException is thrown during
\r
310 public void marshal(final org.xml.sax.ContentHandler handler)
\r
311 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
\r
312 org.exolab.castor.xml.ValidationException {
\r
313 Marshaller.marshal(this, handler);
\r
318 public void removeAllObjRef() {
\r
319 this._objRef.clear();
\r
323 * Method removeObjRef.
\r
326 * @return true if the object was removed from the collection.
\r
328 public boolean removeObjRef(final java.lang.Object vObjRef) {
\r
329 boolean removed = _objRef.remove(vObjRef);
\r
334 * Method removeObjRefAt.
\r
337 * @return the element removed from the collection
\r
339 public java.lang.Object removeObjRefAt(final int index) {
\r
340 java.lang.Object obj = this._objRef.remove(index);
\r
345 * Sets the value of field 'name'.
\r
348 * the value of field 'name'.
\r
350 public void setName(final java.lang.String name) {
\r
359 * @throws java.lang.IndexOutOfBoundsException
\r
360 * if the index given is outside the bounds of the collection
\r
362 public void setObjRef(final int index, final java.lang.Object vObjRef)
\r
363 throws java.lang.IndexOutOfBoundsException {
\r
364 // check bounds for index
\r
365 if (index < 0 || index >= this._objRef.size()) {
\r
366 throw new IndexOutOfBoundsException("setObjRef: Index value '" + index
\r
367 + "' not in range [0.." + (this._objRef.size() - 1) + "]");
\r
370 this._objRef.set(index, vObjRef);
\r
376 * @param vObjRefArray
\r
378 public void setObjRef(final java.lang.Object[] vObjRefArray) {
\r
382 for (int i = 0; i < vObjRefArray.length; i++) {
\r
383 this._objRef.add(vObjRefArray[i]);
\r
388 * Sets the value of '_objRef' by copying the given Vector. All elements will
\r
389 * be checked for type safety.
\r
391 * @param vObjRefList
\r
392 * the Vector to copy.
\r
394 public void setObjRef(final java.util.Vector vObjRefList) {
\r
396 this._objRef.clear();
\r
398 this._objRef.addAll(vObjRefList);
\r
402 * Sets the value of '_objRef' by setting it to the given Vector. No type
\r
403 * checking is performed.
\r
407 * @param objRefVector
\r
408 * the Vector to set.
\r
410 public void setObjRefAsReference(final java.util.Vector objRefVector) {
\r
411 this._objRef = objRefVector;
\r
415 * Method unmarshal.
\r
418 * @throws org.exolab.castor.xml.MarshalException
\r
419 * if object is null or if any SAXException is thrown during
\r
421 * @throws org.exolab.castor.xml.ValidationException
\r
422 * if this object is an invalid instance according to the schema
\r
423 * @return the unmarshaled uk.ac.vamsas.objects.core.RangeType
\r
425 public static uk.ac.vamsas.objects.core.RangeType unmarshal(
\r
426 final java.io.Reader reader)
\r
427 throws org.exolab.castor.xml.MarshalException,
\r
428 org.exolab.castor.xml.ValidationException {
\r
429 return (uk.ac.vamsas.objects.core.RangeType) Unmarshaller.unmarshal(
\r
430 uk.ac.vamsas.objects.core.Input.class, reader);
\r
436 * @throws org.exolab.castor.xml.ValidationException
\r
437 * if this object is an invalid instance according to the schema
\r
439 public void validate() throws org.exolab.castor.xml.ValidationException {
\r
440 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
\r
441 validator.validate(this);
\r