2 * This file is part of the Vamsas Client version 0.2.
3 * Copyright 2010 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 AlignmentSequence.
34 * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
37 public class AlignmentSequence extends uk.ac.vamsas.objects.core.SequenceType
38 implements java.io.Serializable {
40 // --------------------------/
41 // - Class/Member Variables -/
42 // --------------------------/
45 * Primary Key for vamsas object referencing
47 private java.lang.String _id;
50 * Dataset Sequence from which this alignment sequence is taken from
53 private java.lang.Object _refid;
56 * Field _alignmentSequenceAnnotationList.
58 private java.util.Vector _alignmentSequenceAnnotationList;
64 public AlignmentSequence() {
66 this._alignmentSequenceAnnotationList = new java.util.Vector();
76 * @param vAlignmentSequenceAnnotation
77 * @throws java.lang.IndexOutOfBoundsException
78 * if the index given is outside the bounds of the collection
80 public void addAlignmentSequenceAnnotation(
81 final uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation vAlignmentSequenceAnnotation)
82 throws java.lang.IndexOutOfBoundsException {
83 this._alignmentSequenceAnnotationList
84 .addElement(vAlignmentSequenceAnnotation);
91 * @param vAlignmentSequenceAnnotation
92 * @throws java.lang.IndexOutOfBoundsException
93 * if the index given is outside the bounds of the collection
95 public void addAlignmentSequenceAnnotation(
97 final uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation vAlignmentSequenceAnnotation)
98 throws java.lang.IndexOutOfBoundsException {
99 this._alignmentSequenceAnnotationList.add(index,
100 vAlignmentSequenceAnnotation);
104 * Method enumerateAlignmentSequenceAnnotation.
106 * @return an Enumeration over all
107 * uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation element
109 public java.util.Enumeration enumerateAlignmentSequenceAnnotation() {
110 return this._alignmentSequenceAnnotationList.elements();
114 * Overrides the java.lang.Object.equals method.
117 * @return true if the objects are equal.
119 public boolean equals(final java.lang.Object obj) {
123 if (super.equals(obj) == false)
126 if (obj instanceof AlignmentSequence) {
128 AlignmentSequence temp = (AlignmentSequence) obj;
131 if (this._id != null) {
132 if (temp._id == null)
134 if (this._id != temp._id) {
135 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._id);
136 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._id);
137 if (thcycle != tmcycle) {
139 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
143 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
149 if (!this._id.equals(temp._id)) {
150 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
151 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
154 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
155 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
158 } else if (temp._id != null)
160 if (this._refid != null) {
161 if (temp._refid == null)
163 if (this._refid != temp._refid) {
164 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._refid);
165 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._refid);
166 if (thcycle != tmcycle) {
168 org.castor.util.CycleBreaker.releaseCycleHandle(this._refid);
172 org.castor.util.CycleBreaker.releaseCycleHandle(temp._refid);
178 if (!this._refid.equals(temp._refid)) {
179 org.castor.util.CycleBreaker.releaseCycleHandle(this._refid);
180 org.castor.util.CycleBreaker.releaseCycleHandle(temp._refid);
183 org.castor.util.CycleBreaker.releaseCycleHandle(this._refid);
184 org.castor.util.CycleBreaker.releaseCycleHandle(temp._refid);
187 } else if (temp._refid != null)
189 if (this._alignmentSequenceAnnotationList != null) {
190 if (temp._alignmentSequenceAnnotationList == null)
192 if (this._alignmentSequenceAnnotationList != temp._alignmentSequenceAnnotationList) {
193 thcycle = org.castor.util.CycleBreaker
194 .startingToCycle(this._alignmentSequenceAnnotationList);
195 tmcycle = org.castor.util.CycleBreaker
196 .startingToCycle(temp._alignmentSequenceAnnotationList);
197 if (thcycle != tmcycle) {
199 org.castor.util.CycleBreaker
200 .releaseCycleHandle(this._alignmentSequenceAnnotationList);
204 org.castor.util.CycleBreaker
205 .releaseCycleHandle(temp._alignmentSequenceAnnotationList);
211 if (!this._alignmentSequenceAnnotationList
212 .equals(temp._alignmentSequenceAnnotationList)) {
213 org.castor.util.CycleBreaker
214 .releaseCycleHandle(this._alignmentSequenceAnnotationList);
215 org.castor.util.CycleBreaker
216 .releaseCycleHandle(temp._alignmentSequenceAnnotationList);
219 org.castor.util.CycleBreaker
220 .releaseCycleHandle(this._alignmentSequenceAnnotationList);
221 org.castor.util.CycleBreaker
222 .releaseCycleHandle(temp._alignmentSequenceAnnotationList);
225 } else if (temp._alignmentSequenceAnnotationList != null)
233 * Method getAlignmentSequenceAnnotation.
236 * @throws java.lang.IndexOutOfBoundsException
237 * if the index given is outside the bounds of the collection
238 * @return the value of the
239 * uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation at the given
242 public uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation getAlignmentSequenceAnnotation(
243 final int index) throws java.lang.IndexOutOfBoundsException {
244 // check bounds for index
245 if (index < 0 || index >= this._alignmentSequenceAnnotationList.size()) {
246 throw new IndexOutOfBoundsException(
247 "getAlignmentSequenceAnnotation: Index value '" + index
248 + "' not in range [0.."
249 + (this._alignmentSequenceAnnotationList.size() - 1) + "]");
252 return (uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation) _alignmentSequenceAnnotationList
257 * Method getAlignmentSequenceAnnotation.Returns the contents of the
258 * collection in an Array.
260 * Note: Just in case the collection contents are changing in another thread,
261 * we pass a 0-length Array of the correct type into the API call. This way we
262 * <i>know</i> that the Array returned is of exactly the correct length.
264 * @return this collection as an Array
266 public uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation[] getAlignmentSequenceAnnotation() {
267 uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation[] array = new uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation[0];
268 return (uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation[]) this._alignmentSequenceAnnotationList
273 * Method getAlignmentSequenceAnnotationAsReference.Returns a reference to
274 * '_alignmentSequenceAnnotationList'. No type checking is performed on any
275 * modifications to the Vector.
277 * @return a reference to the Vector backing this class
279 public java.util.Vector getAlignmentSequenceAnnotationAsReference() {
280 return this._alignmentSequenceAnnotationList;
284 * Method getAlignmentSequenceAnnotationCount.
286 * @return the size of this collection
288 public int getAlignmentSequenceAnnotationCount() {
289 return this._alignmentSequenceAnnotationList.size();
293 * Returns the value of field 'id'. The field 'id' has the following
294 * description: Primary Key for vamsas object referencing
296 * @return the value of field 'Id'.
298 public java.lang.String getId() {
303 * Returns the value of field 'refid'. The field 'refid' has the following
304 * description: Dataset Sequence from which this alignment sequence is taken
308 * @return the value of field 'Refid'.
310 public java.lang.Object getRefid() {
315 * Overrides the java.lang.Object.hashCode method.
317 * The following steps came from <b>Effective Java Programming Language
318 * Guide</b> by Joshua Bloch, Chapter 3
320 * @return a hash code value for the object.
322 public int hashCode() {
323 int result = super.hashCode();
326 if (_id != null && !org.castor.util.CycleBreaker.startingToCycle(_id)) {
327 result = 37 * result + _id.hashCode();
328 org.castor.util.CycleBreaker.releaseCycleHandle(_id);
330 if (_refid != null && !org.castor.util.CycleBreaker.startingToCycle(_refid)) {
331 result = 37 * result + _refid.hashCode();
332 org.castor.util.CycleBreaker.releaseCycleHandle(_refid);
334 if (_alignmentSequenceAnnotationList != null
335 && !org.castor.util.CycleBreaker
336 .startingToCycle(_alignmentSequenceAnnotationList)) {
337 result = 37 * result + _alignmentSequenceAnnotationList.hashCode();
338 org.castor.util.CycleBreaker
339 .releaseCycleHandle(_alignmentSequenceAnnotationList);
348 * @return true if this object is valid according to the schema
350 public boolean isValid() {
353 } catch (org.exolab.castor.xml.ValidationException vex) {
363 * @throws org.exolab.castor.xml.MarshalException
364 * if object is null or if any SAXException is thrown during
366 * @throws org.exolab.castor.xml.ValidationException
367 * if this object is an invalid instance according to the schema
369 public void marshal(final java.io.Writer out)
370 throws org.exolab.castor.xml.MarshalException,
371 org.exolab.castor.xml.ValidationException {
372 Marshaller.marshal(this, out);
379 * @throws java.io.IOException
380 * if an IOException occurs during marshaling
381 * @throws org.exolab.castor.xml.ValidationException
382 * if this object is an invalid instance according to the schema
383 * @throws org.exolab.castor.xml.MarshalException
384 * if object is null or if any SAXException is thrown during
387 public void marshal(final org.xml.sax.ContentHandler handler)
388 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
389 org.exolab.castor.xml.ValidationException {
390 Marshaller.marshal(this, handler);
394 * Method removeAlignmentSequenceAnnotation.
396 * @param vAlignmentSequenceAnnotation
397 * @return true if the object was removed from the collection.
399 public boolean removeAlignmentSequenceAnnotation(
400 final uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation vAlignmentSequenceAnnotation) {
401 boolean removed = _alignmentSequenceAnnotationList
402 .remove(vAlignmentSequenceAnnotation);
407 * Method removeAlignmentSequenceAnnotationAt.
410 * @return the element removed from the collection
412 public uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation removeAlignmentSequenceAnnotationAt(
414 java.lang.Object obj = this._alignmentSequenceAnnotationList.remove(index);
415 return (uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation) obj;
420 public void removeAllAlignmentSequenceAnnotation() {
421 this._alignmentSequenceAnnotationList.clear();
428 * @param vAlignmentSequenceAnnotation
429 * @throws java.lang.IndexOutOfBoundsException
430 * if the index given is outside the bounds of the collection
432 public void setAlignmentSequenceAnnotation(
434 final uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation vAlignmentSequenceAnnotation)
435 throws java.lang.IndexOutOfBoundsException {
436 // check bounds for index
437 if (index < 0 || index >= this._alignmentSequenceAnnotationList.size()) {
438 throw new IndexOutOfBoundsException(
439 "setAlignmentSequenceAnnotation: Index value '" + index
440 + "' not in range [0.."
441 + (this._alignmentSequenceAnnotationList.size() - 1) + "]");
444 this._alignmentSequenceAnnotationList.set(index,
445 vAlignmentSequenceAnnotation);
451 * @param vAlignmentSequenceAnnotationArray
453 public void setAlignmentSequenceAnnotation(
454 final uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation[] vAlignmentSequenceAnnotationArray) {
456 _alignmentSequenceAnnotationList.clear();
458 for (int i = 0; i < vAlignmentSequenceAnnotationArray.length; i++) {
459 this._alignmentSequenceAnnotationList
460 .add(vAlignmentSequenceAnnotationArray[i]);
465 * Sets the value of '_alignmentSequenceAnnotationList' by copying the given
466 * Vector. All elements will be checked for type safety.
468 * @param vAlignmentSequenceAnnotationList
469 * the Vector to copy.
471 public void setAlignmentSequenceAnnotation(
472 final java.util.Vector vAlignmentSequenceAnnotationList) {
474 this._alignmentSequenceAnnotationList.clear();
476 this._alignmentSequenceAnnotationList
477 .addAll(vAlignmentSequenceAnnotationList);
481 * Sets the value of '_alignmentSequenceAnnotationList' by setting it to the
482 * given Vector. No type checking is performed.
486 * @param alignmentSequenceAnnotationVector
489 public void setAlignmentSequenceAnnotationAsReference(
490 final java.util.Vector alignmentSequenceAnnotationVector) {
491 this._alignmentSequenceAnnotationList = alignmentSequenceAnnotationVector;
495 * Sets the value of field 'id'. The field 'id' has the following description:
496 * Primary Key for vamsas object referencing
499 * the value of field 'id'.
501 public void setId(final java.lang.String id) {
506 * Sets the value of field 'refid'. The field 'refid' has the following
507 * description: Dataset Sequence from which this alignment sequence is taken
512 * the value of field 'refid'.
514 public void setRefid(final java.lang.Object refid) {
522 * @throws org.exolab.castor.xml.MarshalException
523 * if object is null or if any SAXException is thrown during
525 * @throws org.exolab.castor.xml.ValidationException
526 * if this object is an invalid instance according to the schema
527 * @return the unmarshaled uk.ac.vamsas.objects.core.SequenceTyp
529 public static uk.ac.vamsas.objects.core.SequenceType unmarshal(
530 final java.io.Reader reader)
531 throws org.exolab.castor.xml.MarshalException,
532 org.exolab.castor.xml.ValidationException {
533 return (uk.ac.vamsas.objects.core.SequenceType) Unmarshaller.unmarshal(
534 uk.ac.vamsas.objects.core.AlignmentSequence.class, reader);
540 * @throws org.exolab.castor.xml.ValidationException
541 * if this object is an invalid instance according to the schema
543 public void validate() throws org.exolab.castor.xml.ValidationException {
544 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
545 validator.validate(this);