2 * This file is part of the Vamsas Client version 0.2.
\r
3 * Copyright 2010 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
32 * node identity and mapping data between tree representations and vamsas
\r
35 * @version $Revision$ $Date$
\r
37 public class Treenode extends uk.ac.vamsas.objects.core.NodeType implements
\r
38 java.io.Serializable {
\r
40 // --------------------------/
\r
41 // - Class/Member Variables -/
\r
42 // --------------------------/
\r
45 * reference to one or more trees containing the node being described.
\r
47 private java.util.Vector _treeId;
\r
50 * String uniquely identifying a particular node in the referenced tree
\r
51 * according to the format of the tree representation that is referenced.
\r
54 private java.lang.String _nodespec;
\r
56 // ----------------/
\r
57 // - Constructors -/
\r
58 // ----------------/
\r
62 this._treeId = new java.util.Vector();
\r
73 * @throws java.lang.IndexOutOfBoundsException
\r
74 * if the index given is outside the bounds of the collection
\r
76 public void addTreeId(final java.lang.Object vTreeId)
\r
77 throws java.lang.IndexOutOfBoundsException {
\r
78 this._treeId.addElement(vTreeId);
\r
86 * @throws java.lang.IndexOutOfBoundsException
\r
87 * if the index given is outside the bounds of the collection
\r
89 public void addTreeId(final int index, final java.lang.Object vTreeId)
\r
90 throws java.lang.IndexOutOfBoundsException {
\r
91 this._treeId.add(index, vTreeId);
\r
95 * Method enumerateTreeId.
\r
97 * @return an Enumeration over all java.lang.Object elements
\r
99 public java.util.Enumeration enumerateTreeId() {
\r
100 return this._treeId.elements();
\r
104 * Overrides the java.lang.Object.equals method.
\r
107 * @return true if the objects are equal.
\r
109 public boolean equals(final java.lang.Object obj) {
\r
113 if (super.equals(obj) == false)
\r
116 if (obj instanceof Treenode) {
\r
118 Treenode temp = (Treenode) obj;
\r
121 if (this._treeId != null) {
\r
122 if (temp._treeId == null)
\r
124 if (this._treeId != temp._treeId) {
\r
125 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._treeId);
\r
126 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._treeId);
\r
127 if (thcycle != tmcycle) {
\r
129 org.castor.util.CycleBreaker.releaseCycleHandle(this._treeId);
\r
133 org.castor.util.CycleBreaker.releaseCycleHandle(temp._treeId);
\r
139 if (!this._treeId.equals(temp._treeId)) {
\r
140 org.castor.util.CycleBreaker.releaseCycleHandle(this._treeId);
\r
141 org.castor.util.CycleBreaker.releaseCycleHandle(temp._treeId);
\r
144 org.castor.util.CycleBreaker.releaseCycleHandle(this._treeId);
\r
145 org.castor.util.CycleBreaker.releaseCycleHandle(temp._treeId);
\r
148 } else if (temp._treeId != null)
\r
150 if (this._nodespec != null) {
\r
151 if (temp._nodespec == null)
\r
153 if (this._nodespec != temp._nodespec) {
\r
154 thcycle = org.castor.util.CycleBreaker
\r
155 .startingToCycle(this._nodespec);
\r
156 tmcycle = org.castor.util.CycleBreaker
\r
157 .startingToCycle(temp._nodespec);
\r
158 if (thcycle != tmcycle) {
\r
160 org.castor.util.CycleBreaker.releaseCycleHandle(this._nodespec);
\r
164 org.castor.util.CycleBreaker.releaseCycleHandle(temp._nodespec);
\r
170 if (!this._nodespec.equals(temp._nodespec)) {
\r
171 org.castor.util.CycleBreaker.releaseCycleHandle(this._nodespec);
\r
172 org.castor.util.CycleBreaker.releaseCycleHandle(temp._nodespec);
\r
175 org.castor.util.CycleBreaker.releaseCycleHandle(this._nodespec);
\r
176 org.castor.util.CycleBreaker.releaseCycleHandle(temp._nodespec);
\r
179 } else if (temp._nodespec != null)
\r
187 * Returns the value of field 'nodespec'. The field 'nodespec' has the
\r
188 * following description: String uniquely identifying a particular node in the
\r
189 * referenced tree according to the format of the tree representation that is
\r
193 * @return the value of field 'Nodespec'.
\r
195 public java.lang.String getNodespec() {
\r
196 return this._nodespec;
\r
200 * Method getTreeId.
\r
203 * @throws java.lang.IndexOutOfBoundsException
\r
204 * if the index given is outside the bounds of the collection
\r
205 * @return the value of the java.lang.Object at the given index
\r
207 public java.lang.Object getTreeId(final int index)
\r
208 throws java.lang.IndexOutOfBoundsException {
\r
209 // check bounds for index
\r
210 if (index < 0 || index >= this._treeId.size()) {
\r
211 throw new IndexOutOfBoundsException("getTreeId: Index value '" + index
\r
212 + "' not in range [0.." + (this._treeId.size() - 1) + "]");
\r
215 return _treeId.get(index);
\r
219 * Method getTreeId.Returns the contents of the collection in an Array.
\r
221 * Note: Just in case the collection contents are changing in another thread,
\r
222 * we pass a 0-length Array of the correct type into the API call. This way we
\r
223 * <i>know</i> that the Array returned is of exactly the correct length.
\r
225 * @return this collection as an Array
\r
227 public java.lang.Object[] getTreeId() {
\r
228 java.lang.Object[] array = new java.lang.Object[0];
\r
229 return (java.lang.Object[]) this._treeId.toArray(array);
\r
233 * Method getTreeIdAsReference.Returns a reference to '_treeId'. No type
\r
234 * checking is performed on any modifications to the Vector.
\r
236 * @return a reference to the Vector backing this class
\r
238 public java.util.Vector getTreeIdAsReference() {
\r
239 return this._treeId;
\r
243 * Method getTreeIdCount.
\r
245 * @return the size of this collection
\r
247 public int getTreeIdCount() {
\r
248 return this._treeId.size();
\r
252 * Overrides the java.lang.Object.hashCode method.
\r
254 * The following steps came from <b>Effective Java Programming Language
\r
255 * Guide</b> by Joshua Bloch, Chapter 3
\r
257 * @return a hash code value for the object.
\r
259 public int hashCode() {
\r
260 int result = super.hashCode();
\r
263 if (_treeId != null
\r
264 && !org.castor.util.CycleBreaker.startingToCycle(_treeId)) {
\r
265 result = 37 * result + _treeId.hashCode();
\r
266 org.castor.util.CycleBreaker.releaseCycleHandle(_treeId);
\r
268 if (_nodespec != null
\r
269 && !org.castor.util.CycleBreaker.startingToCycle(_nodespec)) {
\r
270 result = 37 * result + _nodespec.hashCode();
\r
271 org.castor.util.CycleBreaker.releaseCycleHandle(_nodespec);
\r
280 * @return true if this object is valid according to the schema
\r
282 public boolean isValid() {
\r
285 } catch (org.exolab.castor.xml.ValidationException vex) {
\r
295 * @throws org.exolab.castor.xml.MarshalException
\r
296 * if object is null or if any SAXException is thrown during
\r
298 * @throws org.exolab.castor.xml.ValidationException
\r
299 * if this object is an invalid instance according to the schema
\r
301 public void marshal(final java.io.Writer out)
\r
302 throws org.exolab.castor.xml.MarshalException,
\r
303 org.exolab.castor.xml.ValidationException {
\r
304 Marshaller.marshal(this, out);
\r
311 * @throws java.io.IOException
\r
312 * if an IOException occurs during marshaling
\r
313 * @throws org.exolab.castor.xml.ValidationException
\r
314 * if this object is an invalid instance according to the schema
\r
315 * @throws org.exolab.castor.xml.MarshalException
\r
316 * if object is null or if any SAXException is thrown during
\r
319 public void marshal(final org.xml.sax.ContentHandler handler)
\r
320 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
\r
321 org.exolab.castor.xml.ValidationException {
\r
322 Marshaller.marshal(this, handler);
\r
327 public void removeAllTreeId() {
\r
328 this._treeId.clear();
\r
332 * Method removeTreeId.
\r
335 * @return true if the object was removed from the collection.
\r
337 public boolean removeTreeId(final java.lang.Object vTreeId) {
\r
338 boolean removed = _treeId.remove(vTreeId);
\r
343 * Method removeTreeIdAt.
\r
346 * @return the element removed from the collection
\r
348 public java.lang.Object removeTreeIdAt(final int index) {
\r
349 java.lang.Object obj = this._treeId.remove(index);
\r
354 * Sets the value of field 'nodespec'. The field 'nodespec' has the following
\r
355 * description: String uniquely identifying a particular node in the
\r
356 * referenced tree according to the format of the tree representation that is
\r
361 * the value of field 'nodespec'.
\r
363 public void setNodespec(final java.lang.String nodespec) {
\r
364 this._nodespec = nodespec;
\r
372 * @throws java.lang.IndexOutOfBoundsException
\r
373 * if the index given is outside the bounds of the collection
\r
375 public void setTreeId(final int index, final java.lang.Object vTreeId)
\r
376 throws java.lang.IndexOutOfBoundsException {
\r
377 // check bounds for index
\r
378 if (index < 0 || index >= this._treeId.size()) {
\r
379 throw new IndexOutOfBoundsException("setTreeId: Index value '" + index
\r
380 + "' not in range [0.." + (this._treeId.size() - 1) + "]");
\r
383 this._treeId.set(index, vTreeId);
\r
389 * @param vTreeIdArray
\r
391 public void setTreeId(final java.lang.Object[] vTreeIdArray) {
\r
395 for (int i = 0; i < vTreeIdArray.length; i++) {
\r
396 this._treeId.add(vTreeIdArray[i]);
\r
401 * Sets the value of '_treeId' by copying the given Vector. All elements will
\r
402 * be checked for type safety.
\r
404 * @param vTreeIdList
\r
405 * the Vector to copy.
\r
407 public void setTreeId(final java.util.Vector vTreeIdList) {
\r
409 this._treeId.clear();
\r
411 this._treeId.addAll(vTreeIdList);
\r
415 * Sets the value of '_treeId' by setting it to the given Vector. No type
\r
416 * checking is performed.
\r
420 * @param treeIdVector
\r
421 * the Vector to set.
\r
423 public void setTreeIdAsReference(final java.util.Vector treeIdVector) {
\r
424 this._treeId = treeIdVector;
\r
428 * Method unmarshal.
\r
431 * @throws org.exolab.castor.xml.MarshalException
\r
432 * if object is null or if any SAXException is thrown during
\r
434 * @throws org.exolab.castor.xml.ValidationException
\r
435 * if this object is an invalid instance according to the schema
\r
436 * @return the unmarshaled uk.ac.vamsas.objects.core.NodeType
\r
438 public static uk.ac.vamsas.objects.core.NodeType unmarshal(
\r
439 final java.io.Reader reader)
\r
440 throws org.exolab.castor.xml.MarshalException,
\r
441 org.exolab.castor.xml.ValidationException {
\r
442 return (uk.ac.vamsas.objects.core.NodeType) Unmarshaller.unmarshal(
\r
443 uk.ac.vamsas.objects.core.Treenode.class, reader);
\r
449 * @throws org.exolab.castor.xml.ValidationException
\r
450 * if this object is an invalid instance according to the schema
\r
452 public void validate() throws org.exolab.castor.xml.ValidationException {
\r
453 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
\r
454 validator.validate(this);
\r