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
25 * Specify an ordered set of positions and/or regions on the principle dimension
\r
26 * of some associated vamsas object Keeping to jaxb-1.0 specification for the
\r
27 * moment - this choice should become a substitution group when we use jaxb-2.0
\r
31 * @version $Revision$ $Date$
\r
33 public abstract class RangeType extends uk.ac.vamsas.client.Vobject implements
\r
34 java.io.Serializable {
\r
36 // --------------------------/
\r
37 // - Class/Member Variables -/
\r
38 // --------------------------/
\r
41 * Internal choice value storage
\r
43 private java.lang.Object _choiceValue;
\r
46 * a position within the associated object's coordinate system
\r
49 private java.util.Vector _posList;
\r
52 * a region from start to end, with flag for inclusivity of terminii
\r
54 private java.util.Vector _segList;
\r
56 // ----------------/
\r
57 // - Constructors -/
\r
58 // ----------------/
\r
60 public RangeType() {
\r
62 this._posList = new java.util.Vector();
\r
63 this._segList = new java.util.Vector();
\r
74 * @throws java.lang.IndexOutOfBoundsException
\r
75 * if the index given is outside the bounds of the collection
\r
77 public void addPos(final uk.ac.vamsas.objects.core.Pos vPos)
\r
78 throws java.lang.IndexOutOfBoundsException {
\r
79 this._posList.addElement(vPos);
\r
87 * @throws java.lang.IndexOutOfBoundsException
\r
88 * if the index given is outside the bounds of the collection
\r
90 public void addPos(final int index, final uk.ac.vamsas.objects.core.Pos vPos)
\r
91 throws java.lang.IndexOutOfBoundsException {
\r
92 this._posList.add(index, vPos);
\r
99 * @throws java.lang.IndexOutOfBoundsException
\r
100 * if the index given is outside the bounds of the collection
\r
102 public void addSeg(final uk.ac.vamsas.objects.core.Seg vSeg)
\r
103 throws java.lang.IndexOutOfBoundsException {
\r
104 this._segList.addElement(vSeg);
\r
112 * @throws java.lang.IndexOutOfBoundsException
\r
113 * if the index given is outside the bounds of the collection
\r
115 public void addSeg(final int index, final uk.ac.vamsas.objects.core.Seg vSeg)
\r
116 throws java.lang.IndexOutOfBoundsException {
\r
117 this._segList.add(index, vSeg);
\r
121 * Method enumeratePos.
\r
123 * @return an Enumeration over all uk.ac.vamsas.objects.core.Pos elements
\r
125 public java.util.Enumeration enumeratePos() {
\r
126 return this._posList.elements();
\r
130 * Method enumerateSeg.
\r
132 * @return an Enumeration over all uk.ac.vamsas.objects.core.Seg elements
\r
134 public java.util.Enumeration enumerateSeg() {
\r
135 return this._segList.elements();
\r
139 * Overrides the java.lang.Object.equals method.
\r
142 * @return true if the objects are equal.
\r
144 public boolean equals(final java.lang.Object obj) {
\r
148 if (super.equals(obj) == false)
\r
151 if (obj instanceof RangeType) {
\r
153 RangeType temp = (RangeType) obj;
\r
156 if (this._choiceValue != null) {
\r
157 if (temp._choiceValue == null)
\r
159 if (this._choiceValue != temp._choiceValue) {
\r
160 thcycle = org.castor.util.CycleBreaker
\r
161 .startingToCycle(this._choiceValue);
\r
162 tmcycle = org.castor.util.CycleBreaker
\r
163 .startingToCycle(temp._choiceValue);
\r
164 if (thcycle != tmcycle) {
\r
166 org.castor.util.CycleBreaker
\r
167 .releaseCycleHandle(this._choiceValue);
\r
171 org.castor.util.CycleBreaker
\r
172 .releaseCycleHandle(temp._choiceValue);
\r
178 if (!this._choiceValue.equals(temp._choiceValue)) {
\r
179 org.castor.util.CycleBreaker
\r
180 .releaseCycleHandle(this._choiceValue);
\r
181 org.castor.util.CycleBreaker
\r
182 .releaseCycleHandle(temp._choiceValue);
\r
185 org.castor.util.CycleBreaker.releaseCycleHandle(this._choiceValue);
\r
186 org.castor.util.CycleBreaker.releaseCycleHandle(temp._choiceValue);
\r
189 } else if (temp._choiceValue != null)
\r
191 if (this._posList != null) {
\r
192 if (temp._posList == null)
\r
194 if (this._posList != temp._posList) {
\r
195 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._posList);
\r
196 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._posList);
\r
197 if (thcycle != tmcycle) {
\r
199 org.castor.util.CycleBreaker.releaseCycleHandle(this._posList);
\r
203 org.castor.util.CycleBreaker.releaseCycleHandle(temp._posList);
\r
209 if (!this._posList.equals(temp._posList)) {
\r
210 org.castor.util.CycleBreaker.releaseCycleHandle(this._posList);
\r
211 org.castor.util.CycleBreaker.releaseCycleHandle(temp._posList);
\r
214 org.castor.util.CycleBreaker.releaseCycleHandle(this._posList);
\r
215 org.castor.util.CycleBreaker.releaseCycleHandle(temp._posList);
\r
218 } else if (temp._posList != null)
\r
220 if (this._segList != null) {
\r
221 if (temp._segList == null)
\r
223 if (this._segList != temp._segList) {
\r
224 thcycle = org.castor.util.CycleBreaker.startingToCycle(this._segList);
\r
225 tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._segList);
\r
226 if (thcycle != tmcycle) {
\r
228 org.castor.util.CycleBreaker.releaseCycleHandle(this._segList);
\r
232 org.castor.util.CycleBreaker.releaseCycleHandle(temp._segList);
\r
238 if (!this._segList.equals(temp._segList)) {
\r
239 org.castor.util.CycleBreaker.releaseCycleHandle(this._segList);
\r
240 org.castor.util.CycleBreaker.releaseCycleHandle(temp._segList);
\r
243 org.castor.util.CycleBreaker.releaseCycleHandle(this._segList);
\r
244 org.castor.util.CycleBreaker.releaseCycleHandle(temp._segList);
\r
247 } else if (temp._segList != null)
\r
255 * Returns the value of field 'choiceValue'. The field 'choiceValue' has the
\r
256 * following description: Internal choice value storage
\r
258 * @return the value of field 'ChoiceValue'.
\r
260 public java.lang.Object getChoiceValue() {
\r
261 return this._choiceValue;
\r
268 * @throws java.lang.IndexOutOfBoundsException
\r
269 * if the index given is outside the bounds of the collection
\r
270 * @return the value of the uk.ac.vamsas.objects.core.Pos at the given index
\r
272 public uk.ac.vamsas.objects.core.Pos getPos(final int index)
\r
273 throws java.lang.IndexOutOfBoundsException {
\r
274 // check bounds for index
\r
275 if (index < 0 || index >= this._posList.size()) {
\r
276 throw new IndexOutOfBoundsException("getPos: Index value '" + index
\r
277 + "' not in range [0.." + (this._posList.size() - 1) + "]");
\r
280 return (uk.ac.vamsas.objects.core.Pos) _posList.get(index);
\r
284 * Method getPos.Returns the contents of the collection in an Array.
\r
286 * Note: Just in case the collection contents are changing in another thread,
\r
287 * we pass a 0-length Array of the correct type into the API call. This way we
\r
288 * <i>know</i> that the Array returned is of exactly the correct length.
\r
290 * @return this collection as an Array
\r
292 public uk.ac.vamsas.objects.core.Pos[] getPos() {
\r
293 uk.ac.vamsas.objects.core.Pos[] array = new uk.ac.vamsas.objects.core.Pos[0];
\r
294 return (uk.ac.vamsas.objects.core.Pos[]) this._posList.toArray(array);
\r
298 * Method getPosAsReference.Returns a reference to '_posList'. No type
\r
299 * checking is performed on any modifications to the Vector.
\r
301 * @return a reference to the Vector backing this class
\r
303 public java.util.Vector getPosAsReference() {
\r
304 return this._posList;
\r
308 * Method getPosCount.
\r
310 * @return the size of this collection
\r
312 public int getPosCount() {
\r
313 return this._posList.size();
\r
320 * @throws java.lang.IndexOutOfBoundsException
\r
321 * if the index given is outside the bounds of the collection
\r
322 * @return the value of the uk.ac.vamsas.objects.core.Seg at the given index
\r
324 public uk.ac.vamsas.objects.core.Seg getSeg(final int index)
\r
325 throws java.lang.IndexOutOfBoundsException {
\r
326 // check bounds for index
\r
327 if (index < 0 || index >= this._segList.size()) {
\r
328 throw new IndexOutOfBoundsException("getSeg: Index value '" + index
\r
329 + "' not in range [0.." + (this._segList.size() - 1) + "]");
\r
332 return (uk.ac.vamsas.objects.core.Seg) _segList.get(index);
\r
336 * Method getSeg.Returns the contents of the collection in an Array.
\r
338 * Note: Just in case the collection contents are changing in another thread,
\r
339 * we pass a 0-length Array of the correct type into the API call. This way we
\r
340 * <i>know</i> that the Array returned is of exactly the correct length.
\r
342 * @return this collection as an Array
\r
344 public uk.ac.vamsas.objects.core.Seg[] getSeg() {
\r
345 uk.ac.vamsas.objects.core.Seg[] array = new uk.ac.vamsas.objects.core.Seg[0];
\r
346 return (uk.ac.vamsas.objects.core.Seg[]) this._segList.toArray(array);
\r
350 * Method getSegAsReference.Returns a reference to '_segList'. No type
\r
351 * checking is performed on any modifications to the Vector.
\r
353 * @return a reference to the Vector backing this class
\r
355 public java.util.Vector getSegAsReference() {
\r
356 return this._segList;
\r
360 * Method getSegCount.
\r
362 * @return the size of this collection
\r
364 public int getSegCount() {
\r
365 return this._segList.size();
\r
369 * Overrides the java.lang.Object.hashCode method.
\r
371 * The following steps came from <b>Effective Java Programming Language
\r
372 * Guide</b> by Joshua Bloch, Chapter 3
\r
374 * @return a hash code value for the object.
\r
376 public int hashCode() {
\r
377 int result = super.hashCode();
\r
380 if (_choiceValue != null
\r
381 && !org.castor.util.CycleBreaker.startingToCycle(_choiceValue)) {
\r
382 result = 37 * result + _choiceValue.hashCode();
\r
383 org.castor.util.CycleBreaker.releaseCycleHandle(_choiceValue);
\r
385 if (_posList != null
\r
386 && !org.castor.util.CycleBreaker.startingToCycle(_posList)) {
\r
387 result = 37 * result + _posList.hashCode();
\r
388 org.castor.util.CycleBreaker.releaseCycleHandle(_posList);
\r
390 if (_segList != null
\r
391 && !org.castor.util.CycleBreaker.startingToCycle(_segList)) {
\r
392 result = 37 * result + _segList.hashCode();
\r
393 org.castor.util.CycleBreaker.releaseCycleHandle(_segList);
\r
402 * @return true if this object is valid according to the schema
\r
404 public boolean isValid() {
\r
407 } catch (org.exolab.castor.xml.ValidationException vex) {
\r
415 public void removeAllPos() {
\r
416 this._posList.clear();
\r
421 public void removeAllSeg() {
\r
422 this._segList.clear();
\r
426 * Method removePos.
\r
429 * @return true if the object was removed from the collection.
\r
431 public boolean removePos(final uk.ac.vamsas.objects.core.Pos vPos) {
\r
432 boolean removed = _posList.remove(vPos);
\r
437 * Method removePosAt.
\r
440 * @return the element removed from the collection
\r
442 public uk.ac.vamsas.objects.core.Pos removePosAt(final int index) {
\r
443 java.lang.Object obj = this._posList.remove(index);
\r
444 return (uk.ac.vamsas.objects.core.Pos) obj;
\r
448 * Method removeSeg.
\r
451 * @return true if the object was removed from the collection.
\r
453 public boolean removeSeg(final uk.ac.vamsas.objects.core.Seg vSeg) {
\r
454 boolean removed = _segList.remove(vSeg);
\r
459 * Method removeSegAt.
\r
462 * @return the element removed from the collection
\r
464 public uk.ac.vamsas.objects.core.Seg removeSegAt(final int index) {
\r
465 java.lang.Object obj = this._segList.remove(index);
\r
466 return (uk.ac.vamsas.objects.core.Seg) obj;
\r
474 * @throws java.lang.IndexOutOfBoundsException
\r
475 * if the index given is outside the bounds of the collection
\r
477 public void setPos(final int index, final uk.ac.vamsas.objects.core.Pos vPos)
\r
478 throws java.lang.IndexOutOfBoundsException {
\r
479 // check bounds for index
\r
480 if (index < 0 || index >= this._posList.size()) {
\r
481 throw new IndexOutOfBoundsException("setPos: Index value '" + index
\r
482 + "' not in range [0.." + (this._posList.size() - 1) + "]");
\r
485 this._posList.set(index, vPos);
\r
493 public void setPos(final uk.ac.vamsas.objects.core.Pos[] vPosArray) {
\r
497 for (int i = 0; i < vPosArray.length; i++) {
\r
498 this._posList.add(vPosArray[i]);
\r
503 * Sets the value of '_posList' by copying the given Vector. All elements will
\r
504 * be checked for type safety.
\r
507 * the Vector to copy.
\r
509 public void setPos(final java.util.Vector vPosList) {
\r
511 this._posList.clear();
\r
513 this._posList.addAll(vPosList);
\r
517 * Sets the value of '_posList' by setting it to the given Vector. No type
\r
518 * checking is performed.
\r
523 * the Vector to set.
\r
525 public void setPosAsReference(final java.util.Vector posVector) {
\r
526 this._posList = posVector;
\r
534 * @throws java.lang.IndexOutOfBoundsException
\r
535 * if the index given is outside the bounds of the collection
\r
537 public void setSeg(final int index, final uk.ac.vamsas.objects.core.Seg vSeg)
\r
538 throws java.lang.IndexOutOfBoundsException {
\r
539 // check bounds for index
\r
540 if (index < 0 || index >= this._segList.size()) {
\r
541 throw new IndexOutOfBoundsException("setSeg: Index value '" + index
\r
542 + "' not in range [0.." + (this._segList.size() - 1) + "]");
\r
545 this._segList.set(index, vSeg);
\r
553 public void setSeg(final uk.ac.vamsas.objects.core.Seg[] vSegArray) {
\r
557 for (int i = 0; i < vSegArray.length; i++) {
\r
558 this._segList.add(vSegArray[i]);
\r
563 * Sets the value of '_segList' by copying the given Vector. All elements will
\r
564 * be checked for type safety.
\r
567 * the Vector to copy.
\r
569 public void setSeg(final java.util.Vector vSegList) {
\r
571 this._segList.clear();
\r
573 this._segList.addAll(vSegList);
\r
577 * Sets the value of '_segList' by setting it to the given Vector. No type
\r
578 * checking is performed.
\r
583 * the Vector to set.
\r
585 public void setSegAsReference(final java.util.Vector segVector) {
\r
586 this._segList = segVector;
\r
592 * @throws org.exolab.castor.xml.ValidationException
\r
593 * if this object is an invalid instance according to the schema
\r
595 public void validate() throws org.exolab.castor.xml.ValidationException {
\r
596 org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
\r
597 validator.validate(this);
\r