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 * Class AnnotationElement.
34 * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
37 public class AnnotationElement extends uk.ac.vamsas.client.Vobject implements
38 java.io.Serializable {
40 // --------------------------/
41 // - Class/Member Variables -/
42 // --------------------------/
45 * position with respect to the coordinate frame defined by a rangeType
48 private long _position;
51 * keeps track of state for field: _position
53 private boolean _has_position;
56 * true means the annotation element appears between the specified position
59 private boolean _after = false;
62 * keeps track of state for field: _after
64 private boolean _has_after;
67 * Primary Key for vamsas object referencing
69 private java.lang.String _id;
72 * Free text at this position
74 private java.lang.String _description;
77 * Discrete symbol - possibly graphically represented
80 private java.util.Vector _glyphList;
83 * Ordered set of float values - an application may treat the values together
84 * as a vector with common support for a set of annotation elements - but this
85 * is, again, not validated so applications should deal gracefully with
86 * varying numbers of dimensions
89 private java.util.Vector _valueList;
95 public AnnotationElement() {
97 this._glyphList = new java.util.Vector();
98 this._valueList = new java.util.Vector();
109 * @throws java.lang.IndexOutOfBoundsException
110 * if the index given is outside the bounds of the collection
112 public void addGlyph(final uk.ac.vamsas.objects.core.Glyph vGlyph)
113 throws java.lang.IndexOutOfBoundsException {
114 this._glyphList.addElement(vGlyph);
122 * @throws java.lang.IndexOutOfBoundsException
123 * if the index given is outside the bounds of the collection
125 public void addGlyph(final int index,
126 final uk.ac.vamsas.objects.core.Glyph vGlyph)
127 throws java.lang.IndexOutOfBoundsException {
128 this._glyphList.add(index, vGlyph);
135 * @throws java.lang.IndexOutOfBoundsException
136 * if the index given is outside the bounds of the collection
138 public void addValue(final float vValue)
139 throws java.lang.IndexOutOfBoundsException {
140 this._valueList.addElement(new java.lang.Float(vValue));
148 * @throws java.lang.IndexOutOfBoundsException
149 * if the index given is outside the bounds of the collection
151 public void addValue(final int index, final float vValue)
152 throws java.lang.IndexOutOfBoundsException {
153 this._valueList.add(index, new java.lang.Float(vValue));
158 public void deleteAfter() {
159 this._has_after = false;
164 public void deletePosition() {
165 this._has_position = false;
169 * Method enumerateGlyph.
171 * @return an Enumeration over all uk.ac.vamsas.objects.core.Glyph elements
173 public java.util.Enumeration enumerateGlyph() {
174 return this._glyphList.elements();
178 * Method enumerateValue.
180 * @return an Enumeration over all float elements
182 public java.util.Enumeration enumerateValue() {
183 return this._valueList.elements();
187 * Overrides the java.lang.Object.equals method.
190 * @return true if the objects are equal.
192 public boolean equals(final java.lang.Object obj) {
196 if (super.equals(obj) == false)
199 if (obj instanceof AnnotationElement) {
201 AnnotationElement temp = (AnnotationElement) obj;
204 if (this._position != temp._position)
206 if (this._has_position != temp._has_position)
208 if (this._after != temp._after)
210 if (this._has_after != temp._has_after)
212 if (this._id != null) {
213 if (temp._id == null)
215 if (this._id != temp._id) {
216 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._id);
217 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._id);
218 if (thcycle != tmcycle) {
220 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
224 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
230 if (!this._id.equals(temp._id)) {
231 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
232 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
235 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
236 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
239 } else if (temp._id != null)
241 if (this._description != null) {
242 if (temp._description == null)
244 if (this._description != temp._description) {
245 thcycle = org.castor.util.CycleBreaker
246 .startingToCycle(this._description);
247 tmcycle = org.castor.util.CycleBreaker
248 .startingToCycle(temp._description);
249 if (thcycle != tmcycle) {
251 org.castor.util.CycleBreaker
252 .releaseCycleHandle(this._description);
256 org.castor.util.CycleBreaker
257 .releaseCycleHandle(temp._description);
263 if (!this._description.equals(temp._description)) {
264 org.castor.util.CycleBreaker
265 .releaseCycleHandle(this._description);
266 org.castor.util.CycleBreaker
267 .releaseCycleHandle(temp._description);
270 org.castor.util.CycleBreaker.releaseCycleHandle(this._description);
271 org.castor.util.CycleBreaker.releaseCycleHandle(temp._description);
274 } else if (temp._description != null)
276 if (this._glyphList != null) {
277 if (temp._glyphList == null)
279 if (this._glyphList != temp._glyphList) {
280 thcycle = org.castor.util.CycleBreaker
281 .startingToCycle(this._glyphList);
282 tmcycle = org.castor.util.CycleBreaker
283 .startingToCycle(temp._glyphList);
284 if (thcycle != tmcycle) {
286 org.castor.util.CycleBreaker.releaseCycleHandle(this._glyphList);
290 org.castor.util.CycleBreaker.releaseCycleHandle(temp._glyphList);
296 if (!this._glyphList.equals(temp._glyphList)) {
297 org.castor.util.CycleBreaker.releaseCycleHandle(this._glyphList);
298 org.castor.util.CycleBreaker.releaseCycleHandle(temp._glyphList);
301 org.castor.util.CycleBreaker.releaseCycleHandle(this._glyphList);
302 org.castor.util.CycleBreaker.releaseCycleHandle(temp._glyphList);
305 } else if (temp._glyphList != null)
307 if (this._valueList != null) {
308 if (temp._valueList == null)
310 if (this._valueList != temp._valueList) {
311 thcycle = org.castor.util.CycleBreaker
312 .startingToCycle(this._valueList);
313 tmcycle = org.castor.util.CycleBreaker
314 .startingToCycle(temp._valueList);
315 if (thcycle != tmcycle) {
317 org.castor.util.CycleBreaker.releaseCycleHandle(this._valueList);
321 org.castor.util.CycleBreaker.releaseCycleHandle(temp._valueList);
327 if (!this._valueList.equals(temp._valueList)) {
328 org.castor.util.CycleBreaker.releaseCycleHandle(this._valueList);
329 org.castor.util.CycleBreaker.releaseCycleHandle(temp._valueList);
332 org.castor.util.CycleBreaker.releaseCycleHandle(this._valueList);
333 org.castor.util.CycleBreaker.releaseCycleHandle(temp._valueList);
336 } else if (temp._valueList != null)
344 * Returns the value of field 'after'. The field 'after' has the following
345 * description: true means the annotation element appears between the
346 * specified position and the next
348 * @return the value of field 'After'.
350 public boolean getAfter() {
355 * Returns the value of field 'description'. The field 'description' has the
356 * following description: Free text at this position
358 * @return the value of field 'Description'.
360 public java.lang.String getDescription() {
361 return this._description;
368 * @throws java.lang.IndexOutOfBoundsException
369 * if the index given is outside the bounds of the collection
370 * @return the value of the uk.ac.vamsas.objects.core.Glyph at the given index
372 public uk.ac.vamsas.objects.core.Glyph getGlyph(final int index)
373 throws java.lang.IndexOutOfBoundsException {
374 // check bounds for index
375 if (index < 0 || index >= this._glyphList.size()) {
376 throw new IndexOutOfBoundsException("getGlyph: Index value '" + index
377 + "' not in range [0.." + (this._glyphList.size() - 1) + "]");
380 return (uk.ac.vamsas.objects.core.Glyph) _glyphList.get(index);
384 * Method getGlyph.Returns the contents of the collection in an Array.
386 * Note: Just in case the collection contents are changing in another thread,
387 * we pass a 0-length Array of the correct type into the API call. This way we
388 * <i>know</i> that the Array returned is of exactly the correct length.
390 * @return this collection as an Array
392 public uk.ac.vamsas.objects.core.Glyph[] getGlyph() {
393 uk.ac.vamsas.objects.core.Glyph[] array = new uk.ac.vamsas.objects.core.Glyph[0];
394 return (uk.ac.vamsas.objects.core.Glyph[]) this._glyphList.toArray(array);
398 * Method getGlyphAsReference.Returns a reference to '_glyphList'. No type
399 * checking is performed on any modifications to the Vector.
401 * @return a reference to the Vector backing this class
403 public java.util.Vector getGlyphAsReference() {
404 return this._glyphList;
408 * Method getGlyphCount.
410 * @return the size of this collection
412 public int getGlyphCount() {
413 return this._glyphList.size();
417 * Returns the value of field 'id'. The field 'id' has the following
418 * description: Primary Key for vamsas object referencing
420 * @return the value of field 'Id'.
422 public java.lang.String getId() {
427 * Returns the value of field 'position'. The field 'position' has the
428 * following description: position with respect to the coordinate frame
429 * defined by a rangeType specification
431 * @return the value of field 'Position'.
433 public long getPosition() {
434 return this._position;
441 * @throws java.lang.IndexOutOfBoundsException
442 * if the index given is outside the bounds of the collection
443 * @return the value of the float at the given index
445 public float getValue(final int index)
446 throws java.lang.IndexOutOfBoundsException {
447 // check bounds for index
448 if (index < 0 || index >= this._valueList.size()) {
449 throw new IndexOutOfBoundsException("getValue: Index value '" + index
450 + "' not in range [0.." + (this._valueList.size() - 1) + "]");
453 return ((java.lang.Float) _valueList.get(index)).floatValue();
457 * Method getValue.Returns the contents of the collection in an Array.
459 * @return this collection as an Array
461 public float[] getValue() {
462 int size = this._valueList.size();
463 float[] array = new float[size];
464 java.util.Iterator iter = _valueList.iterator();
465 for (int index = 0; index < size; index++) {
466 array[index] = ((java.lang.Float) iter.next()).floatValue();
472 * Method getValueAsReference.Returns a reference to '_valueList'. No type
473 * checking is performed on any modifications to the Vector.
475 * @return a reference to the Vector backing this class
477 public java.util.Vector getValueAsReference() {
478 return this._valueList;
482 * Method getValueCount.
484 * @return the size of this collection
486 public int getValueCount() {
487 return this._valueList.size();
493 * @return true if at least one After has been added
495 public boolean hasAfter() {
496 return this._has_after;
500 * Method hasPosition.
502 * @return true if at least one Position has been added
504 public boolean hasPosition() {
505 return this._has_position;
509 * Overrides the java.lang.Object.hashCode method.
511 * The following steps came from <b>Effective Java Programming Language
512 * Guide</b> by Joshua Bloch, Chapter 3
514 * @return a hash code value for the object.
516 public int hashCode() {
517 int result = super.hashCode();
520 result = 37 * result + (int) (_position ^ (_position >>> 32));
521 result = 37 * result + (_after ? 0 : 1);
522 if (_id != null && !org.castor.util.CycleBreaker.startingToCycle(_id)) {
523 result = 37 * result + _id.hashCode();
524 org.castor.util.CycleBreaker.releaseCycleHandle(_id);
526 if (_description != null
527 && !org.castor.util.CycleBreaker.startingToCycle(_description)) {
528 result = 37 * result + _description.hashCode();
529 org.castor.util.CycleBreaker.releaseCycleHandle(_description);
531 if (_glyphList != null
532 && !org.castor.util.CycleBreaker.startingToCycle(_glyphList)) {
533 result = 37 * result + _glyphList.hashCode();
534 org.castor.util.CycleBreaker.releaseCycleHandle(_glyphList);
536 if (_valueList != null
537 && !org.castor.util.CycleBreaker.startingToCycle(_valueList)) {
538 result = 37 * result + _valueList.hashCode();
539 org.castor.util.CycleBreaker.releaseCycleHandle(_valueList);
546 * Returns the value of field 'after'. The field 'after' has the following
547 * description: true means the annotation element appears between the
548 * specified position and the next
550 * @return the value of field 'After'.
552 public boolean isAfter() {
559 * @return true if this object is valid according to the schema
561 public boolean isValid() {
564 } catch (org.exolab.castor.xml.ValidationException vex) {
574 * @throws org.exolab.castor.xml.MarshalException
575 * if object is null or if any SAXException is thrown during
577 * @throws org.exolab.castor.xml.ValidationException
578 * if this object is an invalid instance according to the schema
580 public void marshal(final java.io.Writer out)
581 throws org.exolab.castor.xml.MarshalException,
582 org.exolab.castor.xml.ValidationException {
583 Marshaller.marshal(this, out);
590 * @throws java.io.IOException
591 * if an IOException occurs during marshaling
592 * @throws org.exolab.castor.xml.ValidationException
593 * if this object is an invalid instance according to the schema
594 * @throws org.exolab.castor.xml.MarshalException
595 * if object is null or if any SAXException is thrown during
598 public void marshal(final org.xml.sax.ContentHandler handler)
599 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
600 org.exolab.castor.xml.ValidationException {
601 Marshaller.marshal(this, handler);
606 public void removeAllGlyph() {
607 this._glyphList.clear();
612 public void removeAllValue() {
613 this._valueList.clear();
617 * Method removeGlyph.
620 * @return true if the object was removed from the collection.
622 public boolean removeGlyph(final uk.ac.vamsas.objects.core.Glyph vGlyph) {
623 boolean removed = _glyphList.remove(vGlyph);
628 * Method removeGlyphAt.
631 * @return the element removed from the collection
633 public uk.ac.vamsas.objects.core.Glyph removeGlyphAt(final int index) {
634 java.lang.Object obj = this._glyphList.remove(index);
635 return (uk.ac.vamsas.objects.core.Glyph) obj;
639 * Method removeValue.
642 * @return true if the object was removed from the collection.
644 public boolean removeValue(final float vValue) {
645 boolean removed = _valueList.remove(new java.lang.Float(vValue));
650 * Method removeValueAt.
653 * @return the element removed from the collection
655 public float removeValueAt(final int index) {
656 java.lang.Object obj = this._valueList.remove(index);
657 return ((java.lang.Float) obj).floatValue();
661 * Sets the value of field 'after'. The field 'after' has the following
662 * description: true means the annotation element appears between the
663 * specified position and the next
666 * the value of field 'after'.
668 public void setAfter(final boolean after) {
670 this._has_after = true;
674 * Sets the value of field 'description'. The field 'description' has the
675 * following description: Free text at this position
678 * the value of field 'description'.
680 public void setDescription(final java.lang.String description) {
681 this._description = description;
689 * @throws java.lang.IndexOutOfBoundsException
690 * if the index given is outside the bounds of the collection
692 public void setGlyph(final int index,
693 final uk.ac.vamsas.objects.core.Glyph vGlyph)
694 throws java.lang.IndexOutOfBoundsException {
695 // check bounds for index
696 if (index < 0 || index >= this._glyphList.size()) {
697 throw new IndexOutOfBoundsException("setGlyph: Index value '" + index
698 + "' not in range [0.." + (this._glyphList.size() - 1) + "]");
701 this._glyphList.set(index, vGlyph);
709 public void setGlyph(final uk.ac.vamsas.objects.core.Glyph[] vGlyphArray) {
713 for (int i = 0; i < vGlyphArray.length; i++) {
714 this._glyphList.add(vGlyphArray[i]);
719 * Sets the value of '_glyphList' by copying the given Vector. All elements
720 * will be checked for type safety.
723 * the Vector to copy.
725 public void setGlyph(final java.util.Vector vGlyphList) {
727 this._glyphList.clear();
729 this._glyphList.addAll(vGlyphList);
733 * Sets the value of '_glyphList' by setting it to the given Vector. No type
734 * checking is performed.
741 public void setGlyphAsReference(final java.util.Vector glyphVector) {
742 this._glyphList = glyphVector;
746 * Sets the value of field 'id'. The field 'id' has the following description:
747 * Primary Key for vamsas object referencing
750 * the value of field 'id'.
752 public void setId(final java.lang.String id) {
757 * Sets the value of field 'position'. The field 'position' has the following
758 * description: position with respect to the coordinate frame defined by a
759 * rangeType specification
762 * the value of field 'position'.
764 public void setPosition(final long position) {
765 this._position = position;
766 this._has_position = true;
774 * @throws java.lang.IndexOutOfBoundsException
775 * if the index given is outside the bounds of the collection
777 public void setValue(final int index, final float vValue)
778 throws java.lang.IndexOutOfBoundsException {
779 // check bounds for index
780 if (index < 0 || index >= this._valueList.size()) {
781 throw new IndexOutOfBoundsException("setValue: Index value '" + index
782 + "' not in range [0.." + (this._valueList.size() - 1) + "]");
785 this._valueList.set(index, new java.lang.Float(vValue));
793 public void setValue(final float[] vValueArray) {
797 for (int i = 0; i < vValueArray.length; i++) {
798 this._valueList.add(new java.lang.Float(vValueArray[i]));
803 * Sets the value of '_valueList' by copying the given Vector. All elements
804 * will be checked for type safety.
807 * the Vector to copy.
809 public void setValue(final java.util.Vector vValueList) {
811 this._valueList.clear();
813 this._valueList.addAll(vValueList);
817 * Sets the value of '_valueList' by setting it to the given Vector. No type
818 * checking is performed.
825 public void setValueAsReference(final java.util.Vector valueVector) {
826 this._valueList = valueVector;
833 * @throws org.exolab.castor.xml.MarshalException
834 * if object is null or if any SAXException is thrown during
836 * @throws org.exolab.castor.xml.ValidationException
837 * if this object is an invalid instance according to the schema
838 * @return the unmarshaled uk.ac.vamsas.objects.core.AnnotationElement
840 public static uk.ac.vamsas.objects.core.AnnotationElement unmarshal(
841 final java.io.Reader reader)
842 throws org.exolab.castor.xml.MarshalException,
843 org.exolab.castor.xml.ValidationException {
844 return (uk.ac.vamsas.objects.core.AnnotationElement) Unmarshaller
845 .unmarshal(uk.ac.vamsas.objects.core.AnnotationElement.class, reader);
851 * @throws org.exolab.castor.xml.ValidationException
852 * if this object is an invalid instance according to the schema
854 public void validate() throws org.exolab.castor.xml.ValidationException {
855 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
856 validator.validate(this);