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
32 * This is annotation over the coordinate frame defined by all the columns in
\r
36 * @version $Revision$ $Date$
\r
38 public class AlignmentAnnotation extends
\r
39 uk.ac.vamsas.objects.core.RangeAnnotation implements java.io.Serializable {
\r
41 // --------------------------/
\r
42 // - Class/Member Variables -/
\r
43 // --------------------------/
\r
46 * TODO: decide if this flag is redundant - when true it would suggest that
\r
47 * the annotationElement values together form a graph
\r
49 private boolean _graph;
\r
52 * keeps track of state for field: _graph
\r
54 private boolean _has_graph;
\r
57 * annotation is associated with a range on a particular group of alignment
\r
60 private java.util.Vector _seqrefs;
\r
63 * Field _provenance.
\r
65 private uk.ac.vamsas.objects.core.Provenance _provenance;
\r
67 // ----------------/
\r
68 // - Constructors -/
\r
69 // ----------------/
\r
71 public AlignmentAnnotation() {
\r
73 this._seqrefs = new java.util.Vector();
\r
84 * @throws java.lang.IndexOutOfBoundsException
\r
85 * if the index given is outside the bounds of the collection
\r
87 public void addSeqrefs(final java.lang.Object vSeqrefs)
\r
88 throws java.lang.IndexOutOfBoundsException {
\r
89 this._seqrefs.addElement(vSeqrefs);
\r
97 * @throws java.lang.IndexOutOfBoundsException
\r
98 * if the index given is outside the bounds of the collection
\r
100 public void addSeqrefs(final int index, final java.lang.Object vSeqrefs)
\r
101 throws java.lang.IndexOutOfBoundsException {
\r
102 this._seqrefs.add(index, vSeqrefs);
\r
107 public void deleteGraph() {
\r
108 this._has_graph = false;
\r
112 * Method enumerateSeqrefs.
\r
114 * @return an Enumeration over all java.lang.Object elements
\r
116 public java.util.Enumeration enumerateSeqrefs() {
\r
117 return this._seqrefs.elements();
\r
121 * Overrides the java.lang.Object.equals method.
\r
124 * @return true if the objects are equal.
\r
126 public boolean equals(final java.lang.Object obj) {
\r
130 if (super.equals(obj) == false)
\r
133 if (obj instanceof AlignmentAnnotation) {
\r
135 AlignmentAnnotation temp = (AlignmentAnnotation) obj;
\r
138 if (this._graph != temp._graph)
\r
140 if (this._has_graph != temp._has_graph)
\r
142 if (this._seqrefs != null) {
\r
143 if (temp._seqrefs == null)
\r
145 if (this._seqrefs != temp._seqrefs) {
\r
146 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._seqrefs);
\r
147 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._seqrefs);
\r
148 if (thcycle != tmcycle) {
\r
150 org.castor.util.CycleBreaker.releaseCycleHandle(this._seqrefs);
\r
154 org.castor.util.CycleBreaker.releaseCycleHandle(temp._seqrefs);
\r
160 if (!this._seqrefs.equals(temp._seqrefs)) {
\r
161 org.castor.util.CycleBreaker.releaseCycleHandle(this._seqrefs);
\r
162 org.castor.util.CycleBreaker.releaseCycleHandle(temp._seqrefs);
\r
165 org.castor.util.CycleBreaker.releaseCycleHandle(this._seqrefs);
\r
166 org.castor.util.CycleBreaker.releaseCycleHandle(temp._seqrefs);
\r
169 } else if (temp._seqrefs != null)
\r
171 if (this._provenance != null) {
\r
172 if (temp._provenance == null)
\r
174 if (this._provenance != temp._provenance) {
\r
175 thcycle = org.castor.util.CycleBreaker
\r
176 .startingToCycle(this._provenance);
\r
177 tmcycle = org.castor.util.CycleBreaker
\r
178 .startingToCycle(temp._provenance);
\r
179 if (thcycle != tmcycle) {
\r
181 org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);
\r
185 org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);
\r
191 if (!this._provenance.equals(temp._provenance)) {
\r
192 org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);
\r
193 org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);
\r
196 org.castor.util.CycleBreaker.releaseCycleHandle(this._provenance);
\r
197 org.castor.util.CycleBreaker.releaseCycleHandle(temp._provenance);
\r
200 } else if (temp._provenance != null)
\r
208 * Returns the value of field 'graph'. The field 'graph' has the following
\r
209 * description: TODO: decide if this flag is redundant - when true it would
\r
210 * suggest that the annotationElement values together form a graph
\r
212 * @return the value of field 'Graph'.
\r
214 public boolean getGraph() {
\r
215 return this._graph;
\r
219 * Returns the value of field 'provenance'.
\r
221 * @return the value of field 'Provenance'.
\r
223 public uk.ac.vamsas.objects.core.Provenance getProvenance() {
\r
224 return this._provenance;
\r
228 * Method getSeqrefs.
\r
231 * @throws java.lang.IndexOutOfBoundsException
\r
232 * if the index given is outside the bounds of the collection
\r
233 * @return the value of the java.lang.Object at the given index
\r
235 public java.lang.Object getSeqrefs(final int index)
\r
236 throws java.lang.IndexOutOfBoundsException {
\r
237 // check bounds for index
\r
238 if (index < 0 || index >= this._seqrefs.size()) {
\r
239 throw new IndexOutOfBoundsException("getSeqrefs: Index value '" + index
\r
240 + "' not in range [0.." + (this._seqrefs.size() - 1) + "]");
\r
243 return _seqrefs.get(index);
\r
247 * Method getSeqrefs.Returns the contents of the collection in an Array.
\r
249 * Note: Just in case the collection contents are changing in another thread,
\r
250 * we pass a 0-length Array of the correct type into the API call. This way we
\r
251 * <i>know</i> that the Array returned is of exactly the correct length.
\r
253 * @return this collection as an Array
\r
255 public java.lang.Object[] getSeqrefs() {
\r
256 java.lang.Object[] array = new java.lang.Object[0];
\r
257 return (java.lang.Object[]) this._seqrefs.toArray(array);
\r
261 * Method getSeqrefsAsReference.Returns a reference to '_seqrefs'. No type
\r
262 * checking is performed on any modifications to the Vector.
\r
264 * @return a reference to the Vector backing this class
\r
266 public java.util.Vector getSeqrefsAsReference() {
\r
267 return this._seqrefs;
\r
271 * Method getSeqrefsCount.
\r
273 * @return the size of this collection
\r
275 public int getSeqrefsCount() {
\r
276 return this._seqrefs.size();
\r
282 * @return true if at least one Graph has been added
\r
284 public boolean hasGraph() {
\r
285 return this._has_graph;
\r
289 * Overrides the java.lang.Object.hashCode method.
\r
291 * The following steps came from <b>Effective Java Programming Language
\r
292 * Guide</b> by Joshua Bloch, Chapter 3
\r
294 * @return a hash code value for the object.
\r
296 public int hashCode() {
\r
297 int result = super.hashCode();
\r
300 result = 37 * result + (_graph ? 0 : 1);
\r
301 if (_seqrefs != null
\r
302 && !org.castor.util.CycleBreaker.startingToCycle(_seqrefs)) {
\r
303 result = 37 * result + _seqrefs.hashCode();
\r
304 org.castor.util.CycleBreaker.releaseCycleHandle(_seqrefs);
\r
306 if (_provenance != null
\r
307 && !org.castor.util.CycleBreaker.startingToCycle(_provenance)) {
\r
308 result = 37 * result + _provenance.hashCode();
\r
309 org.castor.util.CycleBreaker.releaseCycleHandle(_provenance);
\r
316 * Returns the value of field 'graph'. The field 'graph' has the following
\r
317 * description: TODO: decide if this flag is redundant - when true it would
\r
318 * suggest that the annotationElement values together form a graph
\r
320 * @return the value of field 'Graph'.
\r
322 public boolean isGraph() {
\r
323 return this._graph;
\r
329 * @return true if this object is valid according to the schema
\r
331 public boolean isValid() {
\r
334 } catch (org.exolab.castor.xml.ValidationException vex) {
\r
344 * @throws org.exolab.castor.xml.MarshalException
\r
345 * if object is null or if any SAXException is thrown during
\r
347 * @throws org.exolab.castor.xml.ValidationException
\r
348 * if this object is an invalid instance according to the schema
\r
350 public void marshal(final java.io.Writer out)
\r
351 throws org.exolab.castor.xml.MarshalException,
\r
352 org.exolab.castor.xml.ValidationException {
\r
353 Marshaller.marshal(this, out);
\r
360 * @throws java.io.IOException
\r
361 * if an IOException occurs during marshaling
\r
362 * @throws org.exolab.castor.xml.ValidationException
\r
363 * if this object is an invalid instance according to the schema
\r
364 * @throws org.exolab.castor.xml.MarshalException
\r
365 * if object is null or if any SAXException is thrown during
\r
368 public void marshal(final org.xml.sax.ContentHandler handler)
\r
369 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
\r
370 org.exolab.castor.xml.ValidationException {
\r
371 Marshaller.marshal(this, handler);
\r
376 public void removeAllSeqrefs() {
\r
377 this._seqrefs.clear();
\r
381 * Method removeSeqrefs.
\r
384 * @return true if the object was removed from the collection.
\r
386 public boolean removeSeqrefs(final java.lang.Object vSeqrefs) {
\r
387 boolean removed = _seqrefs.remove(vSeqrefs);
\r
392 * Method removeSeqrefsAt.
\r
395 * @return the element removed from the collection
\r
397 public java.lang.Object removeSeqrefsAt(final int index) {
\r
398 java.lang.Object obj = this._seqrefs.remove(index);
\r
403 * Sets the value of field 'graph'. The field 'graph' has the following
\r
404 * description: TODO: decide if this flag is redundant - when true it would
\r
405 * suggest that the annotationElement values together form a graph
\r
408 * the value of field 'graph'.
\r
410 public void setGraph(final boolean graph) {
\r
411 this._graph = graph;
\r
412 this._has_graph = true;
\r
416 * Sets the value of field 'provenance'.
\r
418 * @param provenance
\r
419 * the value of field 'provenance'.
\r
421 public void setProvenance(
\r
422 final uk.ac.vamsas.objects.core.Provenance provenance) {
\r
423 this._provenance = provenance;
\r
431 * @throws java.lang.IndexOutOfBoundsException
\r
432 * if the index given is outside the bounds of the collection
\r
434 public void setSeqrefs(final int index, final java.lang.Object vSeqrefs)
\r
435 throws java.lang.IndexOutOfBoundsException {
\r
436 // check bounds for index
\r
437 if (index < 0 || index >= this._seqrefs.size()) {
\r
438 throw new IndexOutOfBoundsException("setSeqrefs: Index value '" + index
\r
439 + "' not in range [0.." + (this._seqrefs.size() - 1) + "]");
\r
442 this._seqrefs.set(index, vSeqrefs);
\r
448 * @param vSeqrefsArray
\r
450 public void setSeqrefs(final java.lang.Object[] vSeqrefsArray) {
\r
454 for (int i = 0; i < vSeqrefsArray.length; i++) {
\r
455 this._seqrefs.add(vSeqrefsArray[i]);
\r
460 * Sets the value of '_seqrefs' by copying the given Vector. All elements will
\r
461 * be checked for type safety.
\r
463 * @param vSeqrefsList
\r
464 * the Vector to copy.
\r
466 public void setSeqrefs(final java.util.Vector vSeqrefsList) {
\r
468 this._seqrefs.clear();
\r
470 this._seqrefs.addAll(vSeqrefsList);
\r
474 * Sets the value of '_seqrefs' by setting it to the given Vector. No type
\r
475 * checking is performed.
\r
479 * @param seqrefsVector
\r
480 * the Vector to set.
\r
482 public void setSeqrefsAsReference(final java.util.Vector seqrefsVector) {
\r
483 this._seqrefs = seqrefsVector;
\r
487 * Method unmarshal.
\r
490 * @throws org.exolab.castor.xml.MarshalException
\r
491 * if object is null or if any SAXException is thrown during
\r
493 * @throws org.exolab.castor.xml.ValidationException
\r
494 * if this object is an invalid instance according to the schema
\r
495 * @return the unmarshaled uk.ac.vamsas.objects.core.RangeType
\r
497 public static uk.ac.vamsas.objects.core.RangeType unmarshal(
\r
498 final java.io.Reader reader)
\r
499 throws org.exolab.castor.xml.MarshalException,
\r
500 org.exolab.castor.xml.ValidationException {
\r
501 return (uk.ac.vamsas.objects.core.RangeType) Unmarshaller.unmarshal(
\r
502 uk.ac.vamsas.objects.core.AlignmentAnnotation.class, reader);
\r
508 * @throws org.exolab.castor.xml.ValidationException
\r
509 * if this object is an invalid instance according to the schema
\r
511 public void validate() throws org.exolab.castor.xml.ValidationException {
\r
512 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
\r
513 validator.validate(this);
\r