applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / core / AlignmentSequence.java
1 /*
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.
5  * 
6  * Earlier versions have also been incorporated into Jalview version 2.4 
7  * since 2008, and TOPALi version 2 since 2007.
8  * 
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.
13  *  
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.
18  * 
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/>.
21  */
22 package uk.ac.vamsas.objects.core;
23
24 //---------------------------------/
25 //- Imported classes and packages -/
26 //---------------------------------/
27
28 import org.exolab.castor.xml.Marshaller;
29 import org.exolab.castor.xml.Unmarshaller;
30
31 /**
32  * Class AlignmentSequence.
33  * 
34  * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
35  *          $
36  */
37 public class AlignmentSequence extends uk.ac.vamsas.objects.core.SequenceType
38     implements java.io.Serializable {
39
40   // --------------------------/
41   // - Class/Member Variables -/
42   // --------------------------/
43
44   /**
45    * Primary Key for vamsas object referencing
46    */
47   private java.lang.String _id;
48
49   /**
50    * Dataset Sequence from which this alignment sequence is taken from
51    * 
52    */
53   private java.lang.Object _refid;
54
55   /**
56    * Field _alignmentSequenceAnnotationList.
57    */
58   private java.util.Vector _alignmentSequenceAnnotationList;
59
60   // ----------------/
61   // - Constructors -/
62   // ----------------/
63
64   public AlignmentSequence() {
65     super();
66     this._alignmentSequenceAnnotationList = new java.util.Vector();
67   }
68
69   // -----------/
70   // - Methods -/
71   // -----------/
72
73   /**
74    * 
75    * 
76    * @param vAlignmentSequenceAnnotation
77    * @throws java.lang.IndexOutOfBoundsException
78    *           if the index given is outside the bounds of the collection
79    */
80   public void addAlignmentSequenceAnnotation(
81       final uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation vAlignmentSequenceAnnotation)
82       throws java.lang.IndexOutOfBoundsException {
83     this._alignmentSequenceAnnotationList
84         .addElement(vAlignmentSequenceAnnotation);
85   }
86
87   /**
88    * 
89    * 
90    * @param index
91    * @param vAlignmentSequenceAnnotation
92    * @throws java.lang.IndexOutOfBoundsException
93    *           if the index given is outside the bounds of the collection
94    */
95   public void addAlignmentSequenceAnnotation(
96       final int index,
97       final uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation vAlignmentSequenceAnnotation)
98       throws java.lang.IndexOutOfBoundsException {
99     this._alignmentSequenceAnnotationList.add(index,
100         vAlignmentSequenceAnnotation);
101   }
102
103   /**
104    * Method enumerateAlignmentSequenceAnnotation.
105    * 
106    * @return an Enumeration over all
107    *         uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation element
108    */
109   public java.util.Enumeration enumerateAlignmentSequenceAnnotation() {
110     return this._alignmentSequenceAnnotationList.elements();
111   }
112
113   /**
114    * Overrides the java.lang.Object.equals method.
115    * 
116    * @param obj
117    * @return true if the objects are equal.
118    */
119   public boolean equals(final java.lang.Object obj) {
120     if (this == obj)
121       return true;
122
123     if (super.equals(obj) == false)
124       return false;
125
126     if (obj instanceof AlignmentSequence) {
127
128       AlignmentSequence temp = (AlignmentSequence) obj;
129       boolean thcycle;
130       boolean tmcycle;
131       if (this._id != null) {
132         if (temp._id == null)
133           return false;
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) {
138             if (!thcycle) {
139               org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
140             }
141             ;
142             if (!tmcycle) {
143               org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
144             }
145             ;
146             return false;
147           }
148           if (!thcycle) {
149             if (!this._id.equals(temp._id)) {
150               org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
151               org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
152               return false;
153             }
154             org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
155             org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
156           }
157         }
158       } else if (temp._id != null)
159         return false;
160       if (this._refid != null) {
161         if (temp._refid == null)
162           return false;
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) {
167             if (!thcycle) {
168               org.castor.util.CycleBreaker.releaseCycleHandle(this._refid);
169             }
170             ;
171             if (!tmcycle) {
172               org.castor.util.CycleBreaker.releaseCycleHandle(temp._refid);
173             }
174             ;
175             return false;
176           }
177           if (!thcycle) {
178             if (!this._refid.equals(temp._refid)) {
179               org.castor.util.CycleBreaker.releaseCycleHandle(this._refid);
180               org.castor.util.CycleBreaker.releaseCycleHandle(temp._refid);
181               return false;
182             }
183             org.castor.util.CycleBreaker.releaseCycleHandle(this._refid);
184             org.castor.util.CycleBreaker.releaseCycleHandle(temp._refid);
185           }
186         }
187       } else if (temp._refid != null)
188         return false;
189       if (this._alignmentSequenceAnnotationList != null) {
190         if (temp._alignmentSequenceAnnotationList == null)
191           return false;
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) {
198             if (!thcycle) {
199               org.castor.util.CycleBreaker
200                   .releaseCycleHandle(this._alignmentSequenceAnnotationList);
201             }
202             ;
203             if (!tmcycle) {
204               org.castor.util.CycleBreaker
205                   .releaseCycleHandle(temp._alignmentSequenceAnnotationList);
206             }
207             ;
208             return false;
209           }
210           if (!thcycle) {
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);
217               return false;
218             }
219             org.castor.util.CycleBreaker
220                 .releaseCycleHandle(this._alignmentSequenceAnnotationList);
221             org.castor.util.CycleBreaker
222                 .releaseCycleHandle(temp._alignmentSequenceAnnotationList);
223           }
224         }
225       } else if (temp._alignmentSequenceAnnotationList != null)
226         return false;
227       return true;
228     }
229     return false;
230   }
231
232   /**
233    * Method getAlignmentSequenceAnnotation.
234    * 
235    * @param index
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
240    *         index
241    */
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) + "]");
250     }
251
252     return (uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation) _alignmentSequenceAnnotationList
253         .get(index);
254   }
255
256   /**
257    * Method getAlignmentSequenceAnnotation.Returns the contents of the
258    * collection in an Array.
259    * <p>
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.
263    * 
264    * @return this collection as an Array
265    */
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
269         .toArray(array);
270   }
271
272   /**
273    * Method getAlignmentSequenceAnnotationAsReference.Returns a reference to
274    * '_alignmentSequenceAnnotationList'. No type checking is performed on any
275    * modifications to the Vector.
276    * 
277    * @return a reference to the Vector backing this class
278    */
279   public java.util.Vector getAlignmentSequenceAnnotationAsReference() {
280     return this._alignmentSequenceAnnotationList;
281   }
282
283   /**
284    * Method getAlignmentSequenceAnnotationCount.
285    * 
286    * @return the size of this collection
287    */
288   public int getAlignmentSequenceAnnotationCount() {
289     return this._alignmentSequenceAnnotationList.size();
290   }
291
292   /**
293    * Returns the value of field 'id'. The field 'id' has the following
294    * description: Primary Key for vamsas object referencing
295    * 
296    * @return the value of field 'Id'.
297    */
298   public java.lang.String getId() {
299     return this._id;
300   }
301
302   /**
303    * Returns the value of field 'refid'. The field 'refid' has the following
304    * description: Dataset Sequence from which this alignment sequence is taken
305    * from
306    * 
307    * 
308    * @return the value of field 'Refid'.
309    */
310   public java.lang.Object getRefid() {
311     return this._refid;
312   }
313
314   /**
315    * Overrides the java.lang.Object.hashCode method.
316    * <p>
317    * The following steps came from <b>Effective Java Programming Language
318    * Guide</b> by Joshua Bloch, Chapter 3
319    * 
320    * @return a hash code value for the object.
321    */
322   public int hashCode() {
323     int result = super.hashCode();
324
325     long tmp;
326     if (_id != null && !org.castor.util.CycleBreaker.startingToCycle(_id)) {
327       result = 37 * result + _id.hashCode();
328       org.castor.util.CycleBreaker.releaseCycleHandle(_id);
329     }
330     if (_refid != null && !org.castor.util.CycleBreaker.startingToCycle(_refid)) {
331       result = 37 * result + _refid.hashCode();
332       org.castor.util.CycleBreaker.releaseCycleHandle(_refid);
333     }
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);
340     }
341
342     return result;
343   }
344
345   /**
346    * Method isValid.
347    * 
348    * @return true if this object is valid according to the schema
349    */
350   public boolean isValid() {
351     try {
352       validate();
353     } catch (org.exolab.castor.xml.ValidationException vex) {
354       return false;
355     }
356     return true;
357   }
358
359   /**
360    * 
361    * 
362    * @param out
363    * @throws org.exolab.castor.xml.MarshalException
364    *           if object is null or if any SAXException is thrown during
365    *           marshaling
366    * @throws org.exolab.castor.xml.ValidationException
367    *           if this object is an invalid instance according to the schema
368    */
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);
373   }
374
375   /**
376    * 
377    * 
378    * @param handler
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
385    *           marshaling
386    */
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);
391   }
392
393   /**
394    * Method removeAlignmentSequenceAnnotation.
395    * 
396    * @param vAlignmentSequenceAnnotation
397    * @return true if the object was removed from the collection.
398    */
399   public boolean removeAlignmentSequenceAnnotation(
400       final uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation vAlignmentSequenceAnnotation) {
401     boolean removed = _alignmentSequenceAnnotationList
402         .remove(vAlignmentSequenceAnnotation);
403     return removed;
404   }
405
406   /**
407    * Method removeAlignmentSequenceAnnotationAt.
408    * 
409    * @param index
410    * @return the element removed from the collection
411    */
412   public uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation removeAlignmentSequenceAnnotationAt(
413       final int index) {
414     java.lang.Object obj = this._alignmentSequenceAnnotationList.remove(index);
415     return (uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation) obj;
416   }
417
418   /**
419      */
420   public void removeAllAlignmentSequenceAnnotation() {
421     this._alignmentSequenceAnnotationList.clear();
422   }
423
424   /**
425    * 
426    * 
427    * @param index
428    * @param vAlignmentSequenceAnnotation
429    * @throws java.lang.IndexOutOfBoundsException
430    *           if the index given is outside the bounds of the collection
431    */
432   public void setAlignmentSequenceAnnotation(
433       final int index,
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) + "]");
442     }
443
444     this._alignmentSequenceAnnotationList.set(index,
445         vAlignmentSequenceAnnotation);
446   }
447
448   /**
449    * 
450    * 
451    * @param vAlignmentSequenceAnnotationArray
452    */
453   public void setAlignmentSequenceAnnotation(
454       final uk.ac.vamsas.objects.core.AlignmentSequenceAnnotation[] vAlignmentSequenceAnnotationArray) {
455     // -- copy array
456     _alignmentSequenceAnnotationList.clear();
457
458     for (int i = 0; i < vAlignmentSequenceAnnotationArray.length; i++) {
459       this._alignmentSequenceAnnotationList
460           .add(vAlignmentSequenceAnnotationArray[i]);
461     }
462   }
463
464   /**
465    * Sets the value of '_alignmentSequenceAnnotationList' by copying the given
466    * Vector. All elements will be checked for type safety.
467    * 
468    * @param vAlignmentSequenceAnnotationList
469    *          the Vector to copy.
470    */
471   public void setAlignmentSequenceAnnotation(
472       final java.util.Vector vAlignmentSequenceAnnotationList) {
473     // copy vector
474     this._alignmentSequenceAnnotationList.clear();
475
476     this._alignmentSequenceAnnotationList
477         .addAll(vAlignmentSequenceAnnotationList);
478   }
479
480   /**
481    * Sets the value of '_alignmentSequenceAnnotationList' by setting it to the
482    * given Vector. No type checking is performed.
483    * 
484    * @deprecated
485    * 
486    * @param alignmentSequenceAnnotationVector
487    *          the Vector to set.
488    */
489   public void setAlignmentSequenceAnnotationAsReference(
490       final java.util.Vector alignmentSequenceAnnotationVector) {
491     this._alignmentSequenceAnnotationList = alignmentSequenceAnnotationVector;
492   }
493
494   /**
495    * Sets the value of field 'id'. The field 'id' has the following description:
496    * Primary Key for vamsas object referencing
497    * 
498    * @param id
499    *          the value of field 'id'.
500    */
501   public void setId(final java.lang.String id) {
502     this._id = id;
503   }
504
505   /**
506    * Sets the value of field 'refid'. The field 'refid' has the following
507    * description: Dataset Sequence from which this alignment sequence is taken
508    * from
509    * 
510    * 
511    * @param refid
512    *          the value of field 'refid'.
513    */
514   public void setRefid(final java.lang.Object refid) {
515     this._refid = refid;
516   }
517
518   /**
519    * Method unmarshal.
520    * 
521    * @param reader
522    * @throws org.exolab.castor.xml.MarshalException
523    *           if object is null or if any SAXException is thrown during
524    *           marshaling
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
528    */
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);
535   }
536
537   /**
538    * 
539    * 
540    * @throws org.exolab.castor.xml.ValidationException
541    *           if this object is an invalid instance according to the schema
542    */
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);
546   }
547
548 }