2 * This file is part of the Vamsas Client version 0.1.
3 * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite,
4 * Andrew Waterhouse and Dominik Lindner.
6 * Earlier versions have also been incorporated into Jalview version 2.4
7 * since 2008, and TOPALi version 2 since 2007.
9 * The Vamsas Client is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * The Vamsas Client is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.
22 package uk.ac.vamsas.objects.core;
24 //---------------------------------/
25 //- Imported classes and packages -/
26 //---------------------------------/
28 import org.exolab.castor.xml.Marshaller;
29 import org.exolab.castor.xml.Unmarshaller;
32 * contains unassociated trees and a number of analysis sets
35 * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
38 public class VAMSAS extends uk.ac.vamsas.client.Vobject implements
39 java.io.Serializable {
41 // --------------------------/
42 // - Class/Member Variables -/
43 // --------------------------/
46 * Primary Key for vamsas object referencing
48 private java.lang.String _id;
53 private java.lang.String _modifiable;
58 private java.util.Vector _treeList;
63 private java.util.Vector _dataSetList;
71 this._treeList = new java.util.Vector();
72 this._dataSetList = new java.util.Vector();
83 * @throws java.lang.IndexOutOfBoundsException
84 * if the index given is outside the bounds of the collection
86 public void addDataSet(final uk.ac.vamsas.objects.core.DataSet vDataSet)
87 throws java.lang.IndexOutOfBoundsException {
88 this._dataSetList.addElement(vDataSet);
96 * @throws java.lang.IndexOutOfBoundsException
97 * if the index given is outside the bounds of the collection
99 public void addDataSet(final int index,
100 final uk.ac.vamsas.objects.core.DataSet vDataSet)
101 throws java.lang.IndexOutOfBoundsException {
102 this._dataSetList.add(index, vDataSet);
109 * @throws java.lang.IndexOutOfBoundsException
110 * if the index given is outside the bounds of the collection
112 public void addTree(final uk.ac.vamsas.objects.core.Tree vTree)
113 throws java.lang.IndexOutOfBoundsException {
114 this._treeList.addElement(vTree);
122 * @throws java.lang.IndexOutOfBoundsException
123 * if the index given is outside the bounds of the collection
125 public void addTree(final int index,
126 final uk.ac.vamsas.objects.core.Tree vTree)
127 throws java.lang.IndexOutOfBoundsException {
128 this._treeList.add(index, vTree);
132 * Method enumerateDataSet.
134 * @return an Enumeration over all uk.ac.vamsas.objects.core.DataSet elements
136 public java.util.Enumeration enumerateDataSet() {
137 return this._dataSetList.elements();
141 * Method enumerateTree.
143 * @return an Enumeration over all uk.ac.vamsas.objects.core.Tree elements
145 public java.util.Enumeration enumerateTree() {
146 return this._treeList.elements();
150 * Overrides the java.lang.Object.equals method.
153 * @return true if the objects are equal.
155 public boolean equals(final java.lang.Object obj) {
159 if (super.equals(obj) == false)
162 if (obj instanceof VAMSAS) {
164 VAMSAS temp = (VAMSAS) obj;
167 if (this._id != null) {
168 if (temp._id == null)
170 if (this._id != temp._id) {
171 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._id);
172 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._id);
173 if (thcycle != tmcycle) {
175 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
179 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
185 if (!this._id.equals(temp._id)) {
186 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
187 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
190 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
191 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
194 } else if (temp._id != null)
196 if (this._modifiable != null) {
197 if (temp._modifiable == null)
199 if (this._modifiable != temp._modifiable) {
200 thcycle = org.castor.util.CycleBreaker
201 .startingToCycle(this._modifiable);
202 tmcycle = org.castor.util.CycleBreaker
203 .startingToCycle(temp._modifiable);
204 if (thcycle != tmcycle) {
206 org.castor.util.CycleBreaker.releaseCycleHandle(this._modifiable);
210 org.castor.util.CycleBreaker.releaseCycleHandle(temp._modifiable);
216 if (!this._modifiable.equals(temp._modifiable)) {
217 org.castor.util.CycleBreaker.releaseCycleHandle(this._modifiable);
218 org.castor.util.CycleBreaker.releaseCycleHandle(temp._modifiable);
221 org.castor.util.CycleBreaker.releaseCycleHandle(this._modifiable);
222 org.castor.util.CycleBreaker.releaseCycleHandle(temp._modifiable);
225 } else if (temp._modifiable != null)
227 if (this._treeList != null) {
228 if (temp._treeList == null)
230 if (this._treeList != temp._treeList) {
231 thcycle = org.castor.util.CycleBreaker
232 .startingToCycle(this._treeList);
233 tmcycle = org.castor.util.CycleBreaker
234 .startingToCycle(temp._treeList);
235 if (thcycle != tmcycle) {
237 org.castor.util.CycleBreaker.releaseCycleHandle(this._treeList);
241 org.castor.util.CycleBreaker.releaseCycleHandle(temp._treeList);
247 if (!this._treeList.equals(temp._treeList)) {
248 org.castor.util.CycleBreaker.releaseCycleHandle(this._treeList);
249 org.castor.util.CycleBreaker.releaseCycleHandle(temp._treeList);
252 org.castor.util.CycleBreaker.releaseCycleHandle(this._treeList);
253 org.castor.util.CycleBreaker.releaseCycleHandle(temp._treeList);
256 } else if (temp._treeList != null)
258 if (this._dataSetList != null) {
259 if (temp._dataSetList == null)
261 if (this._dataSetList != temp._dataSetList) {
262 thcycle = org.castor.util.CycleBreaker
263 .startingToCycle(this._dataSetList);
264 tmcycle = org.castor.util.CycleBreaker
265 .startingToCycle(temp._dataSetList);
266 if (thcycle != tmcycle) {
268 org.castor.util.CycleBreaker
269 .releaseCycleHandle(this._dataSetList);
273 org.castor.util.CycleBreaker
274 .releaseCycleHandle(temp._dataSetList);
280 if (!this._dataSetList.equals(temp._dataSetList)) {
281 org.castor.util.CycleBreaker
282 .releaseCycleHandle(this._dataSetList);
283 org.castor.util.CycleBreaker
284 .releaseCycleHandle(temp._dataSetList);
287 org.castor.util.CycleBreaker.releaseCycleHandle(this._dataSetList);
288 org.castor.util.CycleBreaker.releaseCycleHandle(temp._dataSetList);
291 } else if (temp._dataSetList != null)
302 * @throws java.lang.IndexOutOfBoundsException
303 * if the index given is outside the bounds of the collection
304 * @return the value of the uk.ac.vamsas.objects.core.DataSet at the given
307 public uk.ac.vamsas.objects.core.DataSet getDataSet(final int index)
308 throws java.lang.IndexOutOfBoundsException {
309 // check bounds for index
310 if (index < 0 || index >= this._dataSetList.size()) {
311 throw new IndexOutOfBoundsException("getDataSet: Index value '" + index
312 + "' not in range [0.." + (this._dataSetList.size() - 1) + "]");
315 return (uk.ac.vamsas.objects.core.DataSet) _dataSetList.get(index);
319 * Method getDataSet.Returns the contents of the collection in an Array.
321 * Note: Just in case the collection contents are changing in another thread,
322 * we pass a 0-length Array of the correct type into the API call. This way we
323 * <i>know</i> that the Array returned is of exactly the correct length.
325 * @return this collection as an Array
327 public uk.ac.vamsas.objects.core.DataSet[] getDataSet() {
328 uk.ac.vamsas.objects.core.DataSet[] array = new uk.ac.vamsas.objects.core.DataSet[0];
329 return (uk.ac.vamsas.objects.core.DataSet[]) this._dataSetList
334 * Method getDataSetAsReference.Returns a reference to '_dataSetList'. No type
335 * checking is performed on any modifications to the Vector.
337 * @return a reference to the Vector backing this class
339 public java.util.Vector getDataSetAsReference() {
340 return this._dataSetList;
344 * Method getDataSetCount.
346 * @return the size of this collection
348 public int getDataSetCount() {
349 return this._dataSetList.size();
353 * Returns the value of field 'id'. The field 'id' has the following
354 * description: Primary Key for vamsas object referencing
356 * @return the value of field 'Id'.
358 public java.lang.String getId() {
363 * Returns the value of field 'modifiable'.
365 * @return the value of field 'Modifiable'.
367 public java.lang.String getModifiable() {
368 return this._modifiable;
375 * @throws java.lang.IndexOutOfBoundsException
376 * if the index given is outside the bounds of the collection
377 * @return the value of the uk.ac.vamsas.objects.core.Tree at the given index
379 public uk.ac.vamsas.objects.core.Tree getTree(final int index)
380 throws java.lang.IndexOutOfBoundsException {
381 // check bounds for index
382 if (index < 0 || index >= this._treeList.size()) {
383 throw new IndexOutOfBoundsException("getTree: Index value '" + index
384 + "' not in range [0.." + (this._treeList.size() - 1) + "]");
387 return (uk.ac.vamsas.objects.core.Tree) _treeList.get(index);
391 * Method getTree.Returns the contents of the collection in an Array.
393 * Note: Just in case the collection contents are changing in another thread,
394 * we pass a 0-length Array of the correct type into the API call. This way we
395 * <i>know</i> that the Array returned is of exactly the correct length.
397 * @return this collection as an Array
399 public uk.ac.vamsas.objects.core.Tree[] getTree() {
400 uk.ac.vamsas.objects.core.Tree[] array = new uk.ac.vamsas.objects.core.Tree[0];
401 return (uk.ac.vamsas.objects.core.Tree[]) this._treeList.toArray(array);
405 * Method getTreeAsReference.Returns a reference to '_treeList'. No type
406 * checking is performed on any modifications to the Vector.
408 * @return a reference to the Vector backing this class
410 public java.util.Vector getTreeAsReference() {
411 return this._treeList;
415 * Method getTreeCount.
417 * @return the size of this collection
419 public int getTreeCount() {
420 return this._treeList.size();
424 * Overrides the java.lang.Object.hashCode method.
426 * The following steps came from <b>Effective Java Programming Language
427 * Guide</b> by Joshua Bloch, Chapter 3
429 * @return a hash code value for the object.
431 public int hashCode() {
432 int result = super.hashCode();
435 if (_id != null && !org.castor.util.CycleBreaker.startingToCycle(_id)) {
436 result = 37 * result + _id.hashCode();
437 org.castor.util.CycleBreaker.releaseCycleHandle(_id);
439 if (_modifiable != null
440 && !org.castor.util.CycleBreaker.startingToCycle(_modifiable)) {
441 result = 37 * result + _modifiable.hashCode();
442 org.castor.util.CycleBreaker.releaseCycleHandle(_modifiable);
444 if (_treeList != null
445 && !org.castor.util.CycleBreaker.startingToCycle(_treeList)) {
446 result = 37 * result + _treeList.hashCode();
447 org.castor.util.CycleBreaker.releaseCycleHandle(_treeList);
449 if (_dataSetList != null
450 && !org.castor.util.CycleBreaker.startingToCycle(_dataSetList)) {
451 result = 37 * result + _dataSetList.hashCode();
452 org.castor.util.CycleBreaker.releaseCycleHandle(_dataSetList);
461 * @return true if this object is valid according to the schema
463 public boolean isValid() {
466 } catch (org.exolab.castor.xml.ValidationException vex) {
476 * @throws org.exolab.castor.xml.MarshalException
477 * if object is null or if any SAXException is thrown during
479 * @throws org.exolab.castor.xml.ValidationException
480 * if this object is an invalid instance according to the schema
482 public void marshal(final java.io.Writer out)
483 throws org.exolab.castor.xml.MarshalException,
484 org.exolab.castor.xml.ValidationException {
485 Marshaller.marshal(this, out);
492 * @throws java.io.IOException
493 * if an IOException occurs during marshaling
494 * @throws org.exolab.castor.xml.ValidationException
495 * if this object is an invalid instance according to the schema
496 * @throws org.exolab.castor.xml.MarshalException
497 * if object is null or if any SAXException is thrown during
500 public void marshal(final org.xml.sax.ContentHandler handler)
501 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
502 org.exolab.castor.xml.ValidationException {
503 Marshaller.marshal(this, handler);
508 public void removeAllDataSet() {
509 this._dataSetList.clear();
514 public void removeAllTree() {
515 this._treeList.clear();
519 * Method removeDataSet.
522 * @return true if the object was removed from the collection.
524 public boolean removeDataSet(final uk.ac.vamsas.objects.core.DataSet vDataSet) {
525 boolean removed = _dataSetList.remove(vDataSet);
530 * Method removeDataSetAt.
533 * @return the element removed from the collection
535 public uk.ac.vamsas.objects.core.DataSet removeDataSetAt(final int index) {
536 java.lang.Object obj = this._dataSetList.remove(index);
537 return (uk.ac.vamsas.objects.core.DataSet) obj;
544 * @return true if the object was removed from the collection.
546 public boolean removeTree(final uk.ac.vamsas.objects.core.Tree vTree) {
547 boolean removed = _treeList.remove(vTree);
552 * Method removeTreeAt.
555 * @return the element removed from the collection
557 public uk.ac.vamsas.objects.core.Tree removeTreeAt(final int index) {
558 java.lang.Object obj = this._treeList.remove(index);
559 return (uk.ac.vamsas.objects.core.Tree) obj;
567 * @throws java.lang.IndexOutOfBoundsException
568 * if the index given is outside the bounds of the collection
570 public void setDataSet(final int index,
571 final uk.ac.vamsas.objects.core.DataSet vDataSet)
572 throws java.lang.IndexOutOfBoundsException {
573 // check bounds for index
574 if (index < 0 || index >= this._dataSetList.size()) {
575 throw new IndexOutOfBoundsException("setDataSet: Index value '" + index
576 + "' not in range [0.." + (this._dataSetList.size() - 1) + "]");
579 this._dataSetList.set(index, vDataSet);
585 * @param vDataSetArray
587 public void setDataSet(final uk.ac.vamsas.objects.core.DataSet[] vDataSetArray) {
589 _dataSetList.clear();
591 for (int i = 0; i < vDataSetArray.length; i++) {
592 this._dataSetList.add(vDataSetArray[i]);
597 * Sets the value of '_dataSetList' by copying the given Vector. All elements
598 * will be checked for type safety.
600 * @param vDataSetList
601 * the Vector to copy.
603 public void setDataSet(final java.util.Vector vDataSetList) {
605 this._dataSetList.clear();
607 this._dataSetList.addAll(vDataSetList);
611 * Sets the value of '_dataSetList' by setting it to the given Vector. No type
612 * checking is performed.
616 * @param dataSetVector
619 public void setDataSetAsReference(final java.util.Vector dataSetVector) {
620 this._dataSetList = dataSetVector;
624 * Sets the value of field 'id'. The field 'id' has the following description:
625 * Primary Key for vamsas object referencing
628 * the value of field 'id'.
630 public void setId(final java.lang.String id) {
635 * Sets the value of field 'modifiable'.
638 * the value of field 'modifiable'.
640 public void setModifiable(final java.lang.String modifiable) {
641 this._modifiable = modifiable;
649 * @throws java.lang.IndexOutOfBoundsException
650 * if the index given is outside the bounds of the collection
652 public void setTree(final int index,
653 final uk.ac.vamsas.objects.core.Tree vTree)
654 throws java.lang.IndexOutOfBoundsException {
655 // check bounds for index
656 if (index < 0 || index >= this._treeList.size()) {
657 throw new IndexOutOfBoundsException("setTree: Index value '" + index
658 + "' not in range [0.." + (this._treeList.size() - 1) + "]");
661 this._treeList.set(index, vTree);
669 public void setTree(final uk.ac.vamsas.objects.core.Tree[] vTreeArray) {
673 for (int i = 0; i < vTreeArray.length; i++) {
674 this._treeList.add(vTreeArray[i]);
679 * Sets the value of '_treeList' by copying the given Vector. All elements
680 * will be checked for type safety.
683 * the Vector to copy.
685 public void setTree(final java.util.Vector vTreeList) {
687 this._treeList.clear();
689 this._treeList.addAll(vTreeList);
693 * Sets the value of '_treeList' by setting it to the given Vector. No type
694 * checking is performed.
701 public void setTreeAsReference(final java.util.Vector treeVector) {
702 this._treeList = treeVector;
709 * @throws org.exolab.castor.xml.MarshalException
710 * if object is null or if any SAXException is thrown during
712 * @throws org.exolab.castor.xml.ValidationException
713 * if this object is an invalid instance according to the schema
714 * @return the unmarshaled uk.ac.vamsas.objects.core.VAMSAS
716 public static uk.ac.vamsas.objects.core.VAMSAS unmarshal(
717 final java.io.Reader reader)
718 throws org.exolab.castor.xml.MarshalException,
719 org.exolab.castor.xml.ValidationException {
720 return (uk.ac.vamsas.objects.core.VAMSAS) Unmarshaller.unmarshal(
721 uk.ac.vamsas.objects.core.VAMSAS.class, reader);
727 * @throws org.exolab.castor.xml.ValidationException
728 * if this object is an invalid instance according to the schema
730 public void validate() throws org.exolab.castor.xml.ValidationException {
731 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
732 validator.validate(this);