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;
34 * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
37 public class Sequence extends uk.ac.vamsas.objects.core.SequenceType implements
38 java.io.Serializable {
40 // --------------------------/
41 // - Class/Member Variables -/
42 // --------------------------/
45 * Primary Key for vamsas object referencing
48 private java.lang.String _id;
51 * symbol class for sequence
54 private java.lang.String _dictionary;
57 * Store a list of database references for this sequence record - with
58 * optional mapping from database sequence to the given sequence record
60 private java.util.Vector _dbRefList;
63 * explicitly named cross reference to other objects in the document.
65 private java.util.Vector _vxrefList;
73 this._dbRefList = new java.util.Vector();
74 this._vxrefList = new java.util.Vector();
85 * @throws java.lang.IndexOutOfBoundsException
86 * if the index given is outside the bounds of the collection
88 public void addDbRef(final uk.ac.vamsas.objects.core.DbRef vDbRef)
89 throws java.lang.IndexOutOfBoundsException {
90 this._dbRefList.addElement(vDbRef);
98 * @throws java.lang.IndexOutOfBoundsException
99 * if the index given is outside the bounds of the collection
101 public void addDbRef(final int index,
102 final uk.ac.vamsas.objects.core.DbRef vDbRef)
103 throws java.lang.IndexOutOfBoundsException {
104 this._dbRefList.add(index, vDbRef);
111 * @throws java.lang.IndexOutOfBoundsException
112 * if the index given is outside the bounds of the collection
114 public void addVxref(final uk.ac.vamsas.objects.core.Vxref vVxref)
115 throws java.lang.IndexOutOfBoundsException {
116 this._vxrefList.addElement(vVxref);
124 * @throws java.lang.IndexOutOfBoundsException
125 * if the index given is outside the bounds of the collection
127 public void addVxref(final int index,
128 final uk.ac.vamsas.objects.core.Vxref vVxref)
129 throws java.lang.IndexOutOfBoundsException {
130 this._vxrefList.add(index, vVxref);
134 * Method enumerateDbRef.
136 * @return an Enumeration over all uk.ac.vamsas.objects.core.DbRef elements
138 public java.util.Enumeration enumerateDbRef() {
139 return this._dbRefList.elements();
143 * Method enumerateVxref.
145 * @return an Enumeration over all uk.ac.vamsas.objects.core.Vxref elements
147 public java.util.Enumeration enumerateVxref() {
148 return this._vxrefList.elements();
152 * Overrides the java.lang.Object.equals method.
155 * @return true if the objects are equal.
157 public boolean equals(final java.lang.Object obj) {
161 if (super.equals(obj) == false)
164 if (obj instanceof Sequence) {
166 Sequence temp = (Sequence) obj;
169 if (this._id != null) {
170 if (temp._id == null)
172 if (this._id != temp._id) {
173 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._id);
174 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._id);
175 if (thcycle != tmcycle) {
177 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
181 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
187 if (!this._id.equals(temp._id)) {
188 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
189 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
192 org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
193 org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
196 } else if (temp._id != null)
198 if (this._dictionary != null) {
199 if (temp._dictionary == null)
201 if (this._dictionary != temp._dictionary) {
202 thcycle = org.castor.util.CycleBreaker
203 .startingToCycle(this._dictionary);
204 tmcycle = org.castor.util.CycleBreaker
205 .startingToCycle(temp._dictionary);
206 if (thcycle != tmcycle) {
208 org.castor.util.CycleBreaker.releaseCycleHandle(this._dictionary);
212 org.castor.util.CycleBreaker.releaseCycleHandle(temp._dictionary);
218 if (!this._dictionary.equals(temp._dictionary)) {
219 org.castor.util.CycleBreaker.releaseCycleHandle(this._dictionary);
220 org.castor.util.CycleBreaker.releaseCycleHandle(temp._dictionary);
223 org.castor.util.CycleBreaker.releaseCycleHandle(this._dictionary);
224 org.castor.util.CycleBreaker.releaseCycleHandle(temp._dictionary);
227 } else if (temp._dictionary != null)
229 if (this._dbRefList != null) {
230 if (temp._dbRefList == null)
232 if (this._dbRefList != temp._dbRefList) {
233 thcycle = org.castor.util.CycleBreaker
234 .startingToCycle(this._dbRefList);
235 tmcycle = org.castor.util.CycleBreaker
236 .startingToCycle(temp._dbRefList);
237 if (thcycle != tmcycle) {
239 org.castor.util.CycleBreaker.releaseCycleHandle(this._dbRefList);
243 org.castor.util.CycleBreaker.releaseCycleHandle(temp._dbRefList);
249 if (!this._dbRefList.equals(temp._dbRefList)) {
250 org.castor.util.CycleBreaker.releaseCycleHandle(this._dbRefList);
251 org.castor.util.CycleBreaker.releaseCycleHandle(temp._dbRefList);
254 org.castor.util.CycleBreaker.releaseCycleHandle(this._dbRefList);
255 org.castor.util.CycleBreaker.releaseCycleHandle(temp._dbRefList);
258 } else if (temp._dbRefList != null)
260 if (this._vxrefList != null) {
261 if (temp._vxrefList == null)
263 if (this._vxrefList != temp._vxrefList) {
264 thcycle = org.castor.util.CycleBreaker
265 .startingToCycle(this._vxrefList);
266 tmcycle = org.castor.util.CycleBreaker
267 .startingToCycle(temp._vxrefList);
268 if (thcycle != tmcycle) {
270 org.castor.util.CycleBreaker.releaseCycleHandle(this._vxrefList);
274 org.castor.util.CycleBreaker.releaseCycleHandle(temp._vxrefList);
280 if (!this._vxrefList.equals(temp._vxrefList)) {
281 org.castor.util.CycleBreaker.releaseCycleHandle(this._vxrefList);
282 org.castor.util.CycleBreaker.releaseCycleHandle(temp._vxrefList);
285 org.castor.util.CycleBreaker.releaseCycleHandle(this._vxrefList);
286 org.castor.util.CycleBreaker.releaseCycleHandle(temp._vxrefList);
289 } else if (temp._vxrefList != null)
300 * @throws java.lang.IndexOutOfBoundsException
301 * if the index given is outside the bounds of the collection
302 * @return the value of the uk.ac.vamsas.objects.core.DbRef at the given index
304 public uk.ac.vamsas.objects.core.DbRef getDbRef(final int index)
305 throws java.lang.IndexOutOfBoundsException {
306 // check bounds for index
307 if (index < 0 || index >= this._dbRefList.size()) {
308 throw new IndexOutOfBoundsException("getDbRef: Index value '" + index
309 + "' not in range [0.." + (this._dbRefList.size() - 1) + "]");
312 return (uk.ac.vamsas.objects.core.DbRef) _dbRefList.get(index);
316 * Method getDbRef.Returns the contents of the collection in an Array.
318 * Note: Just in case the collection contents are changing in another thread,
319 * we pass a 0-length Array of the correct type into the API call. This way we
320 * <i>know</i> that the Array returned is of exactly the correct length.
322 * @return this collection as an Array
324 public uk.ac.vamsas.objects.core.DbRef[] getDbRef() {
325 uk.ac.vamsas.objects.core.DbRef[] array = new uk.ac.vamsas.objects.core.DbRef[0];
326 return (uk.ac.vamsas.objects.core.DbRef[]) this._dbRefList.toArray(array);
330 * Method getDbRefAsReference.Returns a reference to '_dbRefList'. No type
331 * checking is performed on any modifications to the Vector.
333 * @return a reference to the Vector backing this class
335 public java.util.Vector getDbRefAsReference() {
336 return this._dbRefList;
340 * Method getDbRefCount.
342 * @return the size of this collection
344 public int getDbRefCount() {
345 return this._dbRefList.size();
349 * Returns the value of field 'dictionary'. The field 'dictionary' has the
350 * following description: symbol class for sequence
353 * @return the value of field 'Dictionary'.
355 public java.lang.String getDictionary() {
356 return this._dictionary;
360 * Returns the value of field 'id'. The field 'id' has the following
361 * description: Primary Key for vamsas object referencing
364 * @return the value of field 'Id'.
366 public java.lang.String getId() {
374 * @throws java.lang.IndexOutOfBoundsException
375 * if the index given is outside the bounds of the collection
376 * @return the value of the uk.ac.vamsas.objects.core.Vxref at the given index
378 public uk.ac.vamsas.objects.core.Vxref getVxref(final int index)
379 throws java.lang.IndexOutOfBoundsException {
380 // check bounds for index
381 if (index < 0 || index >= this._vxrefList.size()) {
382 throw new IndexOutOfBoundsException("getVxref: Index value '" + index
383 + "' not in range [0.." + (this._vxrefList.size() - 1) + "]");
386 return (uk.ac.vamsas.objects.core.Vxref) _vxrefList.get(index);
390 * Method getVxref.Returns the contents of the collection in an Array.
392 * Note: Just in case the collection contents are changing in another thread,
393 * we pass a 0-length Array of the correct type into the API call. This way we
394 * <i>know</i> that the Array returned is of exactly the correct length.
396 * @return this collection as an Array
398 public uk.ac.vamsas.objects.core.Vxref[] getVxref() {
399 uk.ac.vamsas.objects.core.Vxref[] array = new uk.ac.vamsas.objects.core.Vxref[0];
400 return (uk.ac.vamsas.objects.core.Vxref[]) this._vxrefList.toArray(array);
404 * Method getVxrefAsReference.Returns a reference to '_vxrefList'. No type
405 * checking is performed on any modifications to the Vector.
407 * @return a reference to the Vector backing this class
409 public java.util.Vector getVxrefAsReference() {
410 return this._vxrefList;
414 * Method getVxrefCount.
416 * @return the size of this collection
418 public int getVxrefCount() {
419 return this._vxrefList.size();
423 * Overrides the java.lang.Object.hashCode method.
425 * The following steps came from <b>Effective Java Programming Language
426 * Guide</b> by Joshua Bloch, Chapter 3
428 * @return a hash code value for the object.
430 public int hashCode() {
431 int result = super.hashCode();
434 if (_id != null && !org.castor.util.CycleBreaker.startingToCycle(_id)) {
435 result = 37 * result + _id.hashCode();
436 org.castor.util.CycleBreaker.releaseCycleHandle(_id);
438 if (_dictionary != null
439 && !org.castor.util.CycleBreaker.startingToCycle(_dictionary)) {
440 result = 37 * result + _dictionary.hashCode();
441 org.castor.util.CycleBreaker.releaseCycleHandle(_dictionary);
443 if (_dbRefList != null
444 && !org.castor.util.CycleBreaker.startingToCycle(_dbRefList)) {
445 result = 37 * result + _dbRefList.hashCode();
446 org.castor.util.CycleBreaker.releaseCycleHandle(_dbRefList);
448 if (_vxrefList != null
449 && !org.castor.util.CycleBreaker.startingToCycle(_vxrefList)) {
450 result = 37 * result + _vxrefList.hashCode();
451 org.castor.util.CycleBreaker.releaseCycleHandle(_vxrefList);
460 * @return true if this object is valid according to the schema
462 public boolean isValid() {
465 } catch (org.exolab.castor.xml.ValidationException vex) {
475 * @throws org.exolab.castor.xml.MarshalException
476 * if object is null or if any SAXException is thrown during
478 * @throws org.exolab.castor.xml.ValidationException
479 * if this object is an invalid instance according to the schema
481 public void marshal(final java.io.Writer out)
482 throws org.exolab.castor.xml.MarshalException,
483 org.exolab.castor.xml.ValidationException {
484 Marshaller.marshal(this, out);
491 * @throws java.io.IOException
492 * if an IOException occurs during marshaling
493 * @throws org.exolab.castor.xml.ValidationException
494 * if this object is an invalid instance according to the schema
495 * @throws org.exolab.castor.xml.MarshalException
496 * if object is null or if any SAXException is thrown during
499 public void marshal(final org.xml.sax.ContentHandler handler)
500 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
501 org.exolab.castor.xml.ValidationException {
502 Marshaller.marshal(this, handler);
507 public void removeAllDbRef() {
508 this._dbRefList.clear();
513 public void removeAllVxref() {
514 this._vxrefList.clear();
518 * Method removeDbRef.
521 * @return true if the object was removed from the collection.
523 public boolean removeDbRef(final uk.ac.vamsas.objects.core.DbRef vDbRef) {
524 boolean removed = _dbRefList.remove(vDbRef);
529 * Method removeDbRefAt.
532 * @return the element removed from the collection
534 public uk.ac.vamsas.objects.core.DbRef removeDbRefAt(final int index) {
535 java.lang.Object obj = this._dbRefList.remove(index);
536 return (uk.ac.vamsas.objects.core.DbRef) obj;
540 * Method removeVxref.
543 * @return true if the object was removed from the collection.
545 public boolean removeVxref(final uk.ac.vamsas.objects.core.Vxref vVxref) {
546 boolean removed = _vxrefList.remove(vVxref);
551 * Method removeVxrefAt.
554 * @return the element removed from the collection
556 public uk.ac.vamsas.objects.core.Vxref removeVxrefAt(final int index) {
557 java.lang.Object obj = this._vxrefList.remove(index);
558 return (uk.ac.vamsas.objects.core.Vxref) obj;
566 * @throws java.lang.IndexOutOfBoundsException
567 * if the index given is outside the bounds of the collection
569 public void setDbRef(final int index,
570 final uk.ac.vamsas.objects.core.DbRef vDbRef)
571 throws java.lang.IndexOutOfBoundsException {
572 // check bounds for index
573 if (index < 0 || index >= this._dbRefList.size()) {
574 throw new IndexOutOfBoundsException("setDbRef: Index value '" + index
575 + "' not in range [0.." + (this._dbRefList.size() - 1) + "]");
578 this._dbRefList.set(index, vDbRef);
586 public void setDbRef(final uk.ac.vamsas.objects.core.DbRef[] vDbRefArray) {
590 for (int i = 0; i < vDbRefArray.length; i++) {
591 this._dbRefList.add(vDbRefArray[i]);
596 * Sets the value of '_dbRefList' by copying the given Vector. All elements
597 * will be checked for type safety.
600 * the Vector to copy.
602 public void setDbRef(final java.util.Vector vDbRefList) {
604 this._dbRefList.clear();
606 this._dbRefList.addAll(vDbRefList);
610 * Sets the value of '_dbRefList' by setting it to the given Vector. No type
611 * checking is performed.
618 public void setDbRefAsReference(final java.util.Vector dbRefVector) {
619 this._dbRefList = dbRefVector;
623 * Sets the value of field 'dictionary'. The field 'dictionary' has the
624 * following description: symbol class for sequence
628 * the value of field 'dictionary'.
630 public void setDictionary(final java.lang.String dictionary) {
631 this._dictionary = dictionary;
635 * Sets the value of field 'id'. The field 'id' has the following description:
636 * Primary Key for vamsas object referencing
640 * the value of field 'id'.
642 public void setId(final java.lang.String id) {
651 * @throws java.lang.IndexOutOfBoundsException
652 * if the index given is outside the bounds of the collection
654 public void setVxref(final int index,
655 final uk.ac.vamsas.objects.core.Vxref vVxref)
656 throws java.lang.IndexOutOfBoundsException {
657 // check bounds for index
658 if (index < 0 || index >= this._vxrefList.size()) {
659 throw new IndexOutOfBoundsException("setVxref: Index value '" + index
660 + "' not in range [0.." + (this._vxrefList.size() - 1) + "]");
663 this._vxrefList.set(index, vVxref);
671 public void setVxref(final uk.ac.vamsas.objects.core.Vxref[] vVxrefArray) {
675 for (int i = 0; i < vVxrefArray.length; i++) {
676 this._vxrefList.add(vVxrefArray[i]);
681 * Sets the value of '_vxrefList' by copying the given Vector. All elements
682 * will be checked for type safety.
685 * the Vector to copy.
687 public void setVxref(final java.util.Vector vVxrefList) {
689 this._vxrefList.clear();
691 this._vxrefList.addAll(vVxrefList);
695 * Sets the value of '_vxrefList' by setting it to the given Vector. No type
696 * checking is performed.
703 public void setVxrefAsReference(final java.util.Vector vxrefVector) {
704 this._vxrefList = vxrefVector;
711 * @throws org.exolab.castor.xml.MarshalException
712 * if object is null or if any SAXException is thrown during
714 * @throws org.exolab.castor.xml.ValidationException
715 * if this object is an invalid instance according to the schema
716 * @return the unmarshaled uk.ac.vamsas.objects.core.SequenceTyp
718 public static uk.ac.vamsas.objects.core.SequenceType unmarshal(
719 final java.io.Reader reader)
720 throws org.exolab.castor.xml.MarshalException,
721 org.exolab.castor.xml.ValidationException {
722 return (uk.ac.vamsas.objects.core.SequenceType) Unmarshaller.unmarshal(
723 uk.ac.vamsas.objects.core.Sequence.class, reader);
729 * @throws org.exolab.castor.xml.ValidationException
730 * if this object is an invalid instance according to the schema
732 public void validate() throws org.exolab.castor.xml.ValidationException {
733 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
734 validator.validate(this);