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;
34 * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
37 public class SequenceType extends uk.ac.vamsas.client.Vobject implements
38 java.io.Serializable {
40 // --------------------------/
41 // - Class/Member Variables -/
42 // --------------------------/
50 * keeps track of state for field: _start
52 private boolean _has_start;
60 * keeps track of state for field: _end
62 private boolean _has_end;
67 private java.lang.String _sequence;
72 private java.lang.String _name;
77 private java.lang.String _description;
80 * additional typed properties
82 private java.util.Vector _propertyList;
88 public SequenceType() {
90 this._propertyList = new java.util.Vector();
101 * @throws java.lang.IndexOutOfBoundsException
102 * if the index given is outside the bounds of the collection
104 public void addProperty(final uk.ac.vamsas.objects.core.Property vProperty)
105 throws java.lang.IndexOutOfBoundsException {
106 this._propertyList.addElement(vProperty);
114 * @throws java.lang.IndexOutOfBoundsException
115 * if the index given is outside the bounds of the collection
117 public void addProperty(final int index,
118 final uk.ac.vamsas.objects.core.Property vProperty)
119 throws java.lang.IndexOutOfBoundsException {
120 this._propertyList.add(index, vProperty);
125 public void deleteEnd() {
126 this._has_end = false;
131 public void deleteStart() {
132 this._has_start = false;
136 * Method enumerateProperty.
138 * @return an Enumeration over all uk.ac.vamsas.objects.core.Property elements
140 public java.util.Enumeration enumerateProperty() {
141 return this._propertyList.elements();
145 * Overrides the java.lang.Object.equals method.
148 * @return true if the objects are equal.
150 public boolean equals(final java.lang.Object obj) {
154 if (super.equals(obj) == false)
157 if (obj instanceof SequenceType) {
159 SequenceType temp = (SequenceType) obj;
162 if (this._start != temp._start)
164 if (this._has_start != temp._has_start)
166 if (this._end != temp._end)
168 if (this._has_end != temp._has_end)
170 if (this._sequence != null) {
171 if (temp._sequence == null)
173 if (this._sequence != temp._sequence) {
174 thcycle = org.castor.util.CycleBreaker
175 .startingToCycle(this._sequence);
176 tmcycle = org.castor.util.CycleBreaker
177 .startingToCycle(temp._sequence);
178 if (thcycle != tmcycle) {
180 org.castor.util.CycleBreaker.releaseCycleHandle(this._sequence);
184 org.castor.util.CycleBreaker.releaseCycleHandle(temp._sequence);
190 if (!this._sequence.equals(temp._sequence)) {
191 org.castor.util.CycleBreaker.releaseCycleHandle(this._sequence);
192 org.castor.util.CycleBreaker.releaseCycleHandle(temp._sequence);
195 org.castor.util.CycleBreaker.releaseCycleHandle(this._sequence);
196 org.castor.util.CycleBreaker.releaseCycleHandle(temp._sequence);
199 } else if (temp._sequence != null)
201 if (this._name != null) {
202 if (temp._name == null)
204 if (this._name != temp._name) {
205 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._name);
206 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._name);
207 if (thcycle != tmcycle) {
209 org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
213 org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
219 if (!this._name.equals(temp._name)) {
220 org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
221 org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
224 org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
225 org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
228 } else if (temp._name != null)
230 if (this._description != null) {
231 if (temp._description == null)
233 if (this._description != temp._description) {
234 thcycle = org.castor.util.CycleBreaker
235 .startingToCycle(this._description);
236 tmcycle = org.castor.util.CycleBreaker
237 .startingToCycle(temp._description);
238 if (thcycle != tmcycle) {
240 org.castor.util.CycleBreaker
241 .releaseCycleHandle(this._description);
245 org.castor.util.CycleBreaker
246 .releaseCycleHandle(temp._description);
252 if (!this._description.equals(temp._description)) {
253 org.castor.util.CycleBreaker
254 .releaseCycleHandle(this._description);
255 org.castor.util.CycleBreaker
256 .releaseCycleHandle(temp._description);
259 org.castor.util.CycleBreaker.releaseCycleHandle(this._description);
260 org.castor.util.CycleBreaker.releaseCycleHandle(temp._description);
263 } else if (temp._description != null)
265 if (this._propertyList != null) {
266 if (temp._propertyList == null)
268 if (this._propertyList != temp._propertyList) {
269 thcycle = org.castor.util.CycleBreaker
270 .startingToCycle(this._propertyList);
271 tmcycle = org.castor.util.CycleBreaker
272 .startingToCycle(temp._propertyList);
273 if (thcycle != tmcycle) {
275 org.castor.util.CycleBreaker
276 .releaseCycleHandle(this._propertyList);
280 org.castor.util.CycleBreaker
281 .releaseCycleHandle(temp._propertyList);
287 if (!this._propertyList.equals(temp._propertyList)) {
288 org.castor.util.CycleBreaker
289 .releaseCycleHandle(this._propertyList);
290 org.castor.util.CycleBreaker
291 .releaseCycleHandle(temp._propertyList);
294 org.castor.util.CycleBreaker.releaseCycleHandle(this._propertyList);
295 org.castor.util.CycleBreaker.releaseCycleHandle(temp._propertyList);
298 } else if (temp._propertyList != null)
306 * Returns the value of field 'description'.
308 * @return the value of field 'Description'.
310 public java.lang.String getDescription() {
311 return this._description;
315 * Returns the value of field 'end'.
317 * @return the value of field 'End'.
319 public long getEnd() {
324 * Returns the value of field 'name'.
326 * @return the value of field 'Name'.
328 public java.lang.String getName() {
333 * Method getProperty.
336 * @throws java.lang.IndexOutOfBoundsException
337 * if the index given is outside the bounds of the collection
338 * @return the value of the uk.ac.vamsas.objects.core.Property at the given
341 public uk.ac.vamsas.objects.core.Property getProperty(final int index)
342 throws java.lang.IndexOutOfBoundsException {
343 // check bounds for index
344 if (index < 0 || index >= this._propertyList.size()) {
345 throw new IndexOutOfBoundsException("getProperty: Index value '" + index
346 + "' not in range [0.." + (this._propertyList.size() - 1) + "]");
349 return (uk.ac.vamsas.objects.core.Property) _propertyList.get(index);
353 * Method getProperty.Returns the contents of the collection in an Array.
355 * Note: Just in case the collection contents are changing in another thread,
356 * we pass a 0-length Array of the correct type into the API call. This way we
357 * <i>know</i> that the Array returned is of exactly the correct length.
359 * @return this collection as an Array
361 public uk.ac.vamsas.objects.core.Property[] getProperty() {
362 uk.ac.vamsas.objects.core.Property[] array = new uk.ac.vamsas.objects.core.Property[0];
363 return (uk.ac.vamsas.objects.core.Property[]) this._propertyList
368 * Method getPropertyAsReference.Returns a reference to '_propertyList'. No
369 * type checking is performed on any modifications to the Vector.
371 * @return a reference to the Vector backing this class
373 public java.util.Vector getPropertyAsReference() {
374 return this._propertyList;
378 * Method getPropertyCount.
380 * @return the size of this collection
382 public int getPropertyCount() {
383 return this._propertyList.size();
387 * Returns the value of field 'sequence'.
389 * @return the value of field 'Sequence'.
391 public java.lang.String getSequence() {
392 return this._sequence;
396 * Returns the value of field 'start'.
398 * @return the value of field 'Start'.
400 public long getStart() {
407 * @return true if at least one End has been added
409 public boolean hasEnd() {
410 return this._has_end;
416 * @return true if at least one Start has been added
418 public boolean hasStart() {
419 return this._has_start;
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 result = 37 * result + (int) (_start ^ (_start >>> 32));
435 result = 37 * result + (int) (_end ^ (_end >>> 32));
436 if (_sequence != null
437 && !org.castor.util.CycleBreaker.startingToCycle(_sequence)) {
438 result = 37 * result + _sequence.hashCode();
439 org.castor.util.CycleBreaker.releaseCycleHandle(_sequence);
441 if (_name != null && !org.castor.util.CycleBreaker.startingToCycle(_name)) {
442 result = 37 * result + _name.hashCode();
443 org.castor.util.CycleBreaker.releaseCycleHandle(_name);
445 if (_description != null
446 && !org.castor.util.CycleBreaker.startingToCycle(_description)) {
447 result = 37 * result + _description.hashCode();
448 org.castor.util.CycleBreaker.releaseCycleHandle(_description);
450 if (_propertyList != null
451 && !org.castor.util.CycleBreaker.startingToCycle(_propertyList)) {
452 result = 37 * result + _propertyList.hashCode();
453 org.castor.util.CycleBreaker.releaseCycleHandle(_propertyList);
462 * @return true if this object is valid according to the schema
464 public boolean isValid() {
467 } catch (org.exolab.castor.xml.ValidationException vex) {
477 * @throws org.exolab.castor.xml.MarshalException
478 * if object is null or if any SAXException is thrown during
480 * @throws org.exolab.castor.xml.ValidationException
481 * if this object is an invalid instance according to the schema
483 public void marshal(final java.io.Writer out)
484 throws org.exolab.castor.xml.MarshalException,
485 org.exolab.castor.xml.ValidationException {
486 Marshaller.marshal(this, out);
493 * @throws java.io.IOException
494 * if an IOException occurs during marshaling
495 * @throws org.exolab.castor.xml.ValidationException
496 * if this object is an invalid instance according to the schema
497 * @throws org.exolab.castor.xml.MarshalException
498 * if object is null or if any SAXException is thrown during
501 public void marshal(final org.xml.sax.ContentHandler handler)
502 throws java.io.IOException, org.exolab.castor.xml.MarshalException,
503 org.exolab.castor.xml.ValidationException {
504 Marshaller.marshal(this, handler);
509 public void removeAllProperty() {
510 this._propertyList.clear();
514 * Method removeProperty.
517 * @return true if the object was removed from the collection.
519 public boolean removeProperty(
520 final uk.ac.vamsas.objects.core.Property vProperty) {
521 boolean removed = _propertyList.remove(vProperty);
526 * Method removePropertyAt.
529 * @return the element removed from the collection
531 public uk.ac.vamsas.objects.core.Property removePropertyAt(final int index) {
532 java.lang.Object obj = this._propertyList.remove(index);
533 return (uk.ac.vamsas.objects.core.Property) obj;
537 * Sets the value of field 'description'.
540 * the value of field 'description'.
542 public void setDescription(final java.lang.String description) {
543 this._description = description;
547 * Sets the value of field 'end'.
550 * the value of field 'end'.
552 public void setEnd(final long end) {
554 this._has_end = true;
558 * Sets the value of field 'name'.
561 * the value of field 'name'.
563 public void setName(final java.lang.String name) {
572 * @throws java.lang.IndexOutOfBoundsException
573 * if the index given is outside the bounds of the collection
575 public void setProperty(final int index,
576 final uk.ac.vamsas.objects.core.Property vProperty)
577 throws java.lang.IndexOutOfBoundsException {
578 // check bounds for index
579 if (index < 0 || index >= this._propertyList.size()) {
580 throw new IndexOutOfBoundsException("setProperty: Index value '" + index
581 + "' not in range [0.." + (this._propertyList.size() - 1) + "]");
584 this._propertyList.set(index, vProperty);
590 * @param vPropertyArray
592 public void setProperty(
593 final uk.ac.vamsas.objects.core.Property[] vPropertyArray) {
595 _propertyList.clear();
597 for (int i = 0; i < vPropertyArray.length; i++) {
598 this._propertyList.add(vPropertyArray[i]);
603 * Sets the value of '_propertyList' by copying the given Vector. All elements
604 * will be checked for type safety.
606 * @param vPropertyList
607 * the Vector to copy.
609 public void setProperty(final java.util.Vector vPropertyList) {
611 this._propertyList.clear();
613 this._propertyList.addAll(vPropertyList);
617 * Sets the value of '_propertyList' by setting it to the given Vector. No
618 * type checking is performed.
622 * @param propertyVector
625 public void setPropertyAsReference(final java.util.Vector propertyVector) {
626 this._propertyList = propertyVector;
630 * Sets the value of field 'sequence'.
633 * the value of field 'sequence'.
635 public void setSequence(final java.lang.String sequence) {
636 this._sequence = sequence;
640 * Sets the value of field 'start'.
643 * the value of field 'start'.
645 public void setStart(final long start) {
647 this._has_start = true;
654 * @throws org.exolab.castor.xml.MarshalException
655 * if object is null or if any SAXException is thrown during
657 * @throws org.exolab.castor.xml.ValidationException
658 * if this object is an invalid instance according to the schema
659 * @return the unmarshaled uk.ac.vamsas.objects.core.SequenceTyp
661 public static uk.ac.vamsas.objects.core.SequenceType unmarshal(
662 final java.io.Reader reader)
663 throws org.exolab.castor.xml.MarshalException,
664 org.exolab.castor.xml.ValidationException {
665 return (uk.ac.vamsas.objects.core.SequenceType) Unmarshaller.unmarshal(
666 uk.ac.vamsas.objects.core.SequenceType.class, reader);
672 * @throws org.exolab.castor.xml.ValidationException
673 * if this object is an invalid instance according to the schema
675 public void validate() throws org.exolab.castor.xml.ValidationException {
676 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
677 validator.validate(this);