applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / core / SequenceType.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 SequenceType.
33  * 
34  * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
35  *          $
36  */
37 public class SequenceType extends uk.ac.vamsas.client.Vobject implements
38     java.io.Serializable {
39
40   // --------------------------/
41   // - Class/Member Variables -/
42   // --------------------------/
43
44   /**
45    * Field _start.
46    */
47   private long _start;
48
49   /**
50    * keeps track of state for field: _start
51    */
52   private boolean _has_start;
53
54   /**
55    * Field _end.
56    */
57   private long _end;
58
59   /**
60    * keeps track of state for field: _end
61    */
62   private boolean _has_end;
63
64   /**
65    * Field _sequence.
66    */
67   private java.lang.String _sequence;
68
69   /**
70    * Field _name.
71    */
72   private java.lang.String _name;
73
74   /**
75    * Field _description.
76    */
77   private java.lang.String _description;
78
79   /**
80    * additional typed properties
81    */
82   private java.util.Vector _propertyList;
83
84   // ----------------/
85   // - Constructors -/
86   // ----------------/
87
88   public SequenceType() {
89     super();
90     this._propertyList = new java.util.Vector();
91   }
92
93   // -----------/
94   // - Methods -/
95   // -----------/
96
97   /**
98    * 
99    * 
100    * @param vProperty
101    * @throws java.lang.IndexOutOfBoundsException
102    *           if the index given is outside the bounds of the collection
103    */
104   public void addProperty(final uk.ac.vamsas.objects.core.Property vProperty)
105       throws java.lang.IndexOutOfBoundsException {
106     this._propertyList.addElement(vProperty);
107   }
108
109   /**
110    * 
111    * 
112    * @param index
113    * @param vProperty
114    * @throws java.lang.IndexOutOfBoundsException
115    *           if the index given is outside the bounds of the collection
116    */
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);
121   }
122
123   /**
124      */
125   public void deleteEnd() {
126     this._has_end = false;
127   }
128
129   /**
130      */
131   public void deleteStart() {
132     this._has_start = false;
133   }
134
135   /**
136    * Method enumerateProperty.
137    * 
138    * @return an Enumeration over all uk.ac.vamsas.objects.core.Property elements
139    */
140   public java.util.Enumeration enumerateProperty() {
141     return this._propertyList.elements();
142   }
143
144   /**
145    * Overrides the java.lang.Object.equals method.
146    * 
147    * @param obj
148    * @return true if the objects are equal.
149    */
150   public boolean equals(final java.lang.Object obj) {
151     if (this == obj)
152       return true;
153
154     if (super.equals(obj) == false)
155       return false;
156
157     if (obj instanceof SequenceType) {
158
159       SequenceType temp = (SequenceType) obj;
160       boolean thcycle;
161       boolean tmcycle;
162       if (this._start != temp._start)
163         return false;
164       if (this._has_start != temp._has_start)
165         return false;
166       if (this._end != temp._end)
167         return false;
168       if (this._has_end != temp._has_end)
169         return false;
170       if (this._sequence != null) {
171         if (temp._sequence == null)
172           return false;
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) {
179             if (!thcycle) {
180               org.castor.util.CycleBreaker.releaseCycleHandle(this._sequence);
181             }
182             ;
183             if (!tmcycle) {
184               org.castor.util.CycleBreaker.releaseCycleHandle(temp._sequence);
185             }
186             ;
187             return false;
188           }
189           if (!thcycle) {
190             if (!this._sequence.equals(temp._sequence)) {
191               org.castor.util.CycleBreaker.releaseCycleHandle(this._sequence);
192               org.castor.util.CycleBreaker.releaseCycleHandle(temp._sequence);
193               return false;
194             }
195             org.castor.util.CycleBreaker.releaseCycleHandle(this._sequence);
196             org.castor.util.CycleBreaker.releaseCycleHandle(temp._sequence);
197           }
198         }
199       } else if (temp._sequence != null)
200         return false;
201       if (this._name != null) {
202         if (temp._name == null)
203           return false;
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) {
208             if (!thcycle) {
209               org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
210             }
211             ;
212             if (!tmcycle) {
213               org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
214             }
215             ;
216             return false;
217           }
218           if (!thcycle) {
219             if (!this._name.equals(temp._name)) {
220               org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
221               org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
222               return false;
223             }
224             org.castor.util.CycleBreaker.releaseCycleHandle(this._name);
225             org.castor.util.CycleBreaker.releaseCycleHandle(temp._name);
226           }
227         }
228       } else if (temp._name != null)
229         return false;
230       if (this._description != null) {
231         if (temp._description == null)
232           return false;
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) {
239             if (!thcycle) {
240               org.castor.util.CycleBreaker
241                   .releaseCycleHandle(this._description);
242             }
243             ;
244             if (!tmcycle) {
245               org.castor.util.CycleBreaker
246                   .releaseCycleHandle(temp._description);
247             }
248             ;
249             return false;
250           }
251           if (!thcycle) {
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);
257               return false;
258             }
259             org.castor.util.CycleBreaker.releaseCycleHandle(this._description);
260             org.castor.util.CycleBreaker.releaseCycleHandle(temp._description);
261           }
262         }
263       } else if (temp._description != null)
264         return false;
265       if (this._propertyList != null) {
266         if (temp._propertyList == null)
267           return false;
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) {
274             if (!thcycle) {
275               org.castor.util.CycleBreaker
276                   .releaseCycleHandle(this._propertyList);
277             }
278             ;
279             if (!tmcycle) {
280               org.castor.util.CycleBreaker
281                   .releaseCycleHandle(temp._propertyList);
282             }
283             ;
284             return false;
285           }
286           if (!thcycle) {
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);
292               return false;
293             }
294             org.castor.util.CycleBreaker.releaseCycleHandle(this._propertyList);
295             org.castor.util.CycleBreaker.releaseCycleHandle(temp._propertyList);
296           }
297         }
298       } else if (temp._propertyList != null)
299         return false;
300       return true;
301     }
302     return false;
303   }
304
305   /**
306    * Returns the value of field 'description'.
307    * 
308    * @return the value of field 'Description'.
309    */
310   public java.lang.String getDescription() {
311     return this._description;
312   }
313
314   /**
315    * Returns the value of field 'end'.
316    * 
317    * @return the value of field 'End'.
318    */
319   public long getEnd() {
320     return this._end;
321   }
322
323   /**
324    * Returns the value of field 'name'.
325    * 
326    * @return the value of field 'Name'.
327    */
328   public java.lang.String getName() {
329     return this._name;
330   }
331
332   /**
333    * Method getProperty.
334    * 
335    * @param index
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
339    *         index
340    */
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) + "]");
347     }
348
349     return (uk.ac.vamsas.objects.core.Property) _propertyList.get(index);
350   }
351
352   /**
353    * Method getProperty.Returns the contents of the collection in an Array.
354    * <p>
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.
358    * 
359    * @return this collection as an Array
360    */
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
364         .toArray(array);
365   }
366
367   /**
368    * Method getPropertyAsReference.Returns a reference to '_propertyList'. No
369    * type checking is performed on any modifications to the Vector.
370    * 
371    * @return a reference to the Vector backing this class
372    */
373   public java.util.Vector getPropertyAsReference() {
374     return this._propertyList;
375   }
376
377   /**
378    * Method getPropertyCount.
379    * 
380    * @return the size of this collection
381    */
382   public int getPropertyCount() {
383     return this._propertyList.size();
384   }
385
386   /**
387    * Returns the value of field 'sequence'.
388    * 
389    * @return the value of field 'Sequence'.
390    */
391   public java.lang.String getSequence() {
392     return this._sequence;
393   }
394
395   /**
396    * Returns the value of field 'start'.
397    * 
398    * @return the value of field 'Start'.
399    */
400   public long getStart() {
401     return this._start;
402   }
403
404   /**
405    * Method hasEnd.
406    * 
407    * @return true if at least one End has been added
408    */
409   public boolean hasEnd() {
410     return this._has_end;
411   }
412
413   /**
414    * Method hasStart.
415    * 
416    * @return true if at least one Start has been added
417    */
418   public boolean hasStart() {
419     return this._has_start;
420   }
421
422   /**
423    * Overrides the java.lang.Object.hashCode method.
424    * <p>
425    * The following steps came from <b>Effective Java Programming Language
426    * Guide</b> by Joshua Bloch, Chapter 3
427    * 
428    * @return a hash code value for the object.
429    */
430   public int hashCode() {
431     int result = super.hashCode();
432
433     long tmp;
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);
440     }
441     if (_name != null && !org.castor.util.CycleBreaker.startingToCycle(_name)) {
442       result = 37 * result + _name.hashCode();
443       org.castor.util.CycleBreaker.releaseCycleHandle(_name);
444     }
445     if (_description != null
446         && !org.castor.util.CycleBreaker.startingToCycle(_description)) {
447       result = 37 * result + _description.hashCode();
448       org.castor.util.CycleBreaker.releaseCycleHandle(_description);
449     }
450     if (_propertyList != null
451         && !org.castor.util.CycleBreaker.startingToCycle(_propertyList)) {
452       result = 37 * result + _propertyList.hashCode();
453       org.castor.util.CycleBreaker.releaseCycleHandle(_propertyList);
454     }
455
456     return result;
457   }
458
459   /**
460    * Method isValid.
461    * 
462    * @return true if this object is valid according to the schema
463    */
464   public boolean isValid() {
465     try {
466       validate();
467     } catch (org.exolab.castor.xml.ValidationException vex) {
468       return false;
469     }
470     return true;
471   }
472
473   /**
474    * 
475    * 
476    * @param out
477    * @throws org.exolab.castor.xml.MarshalException
478    *           if object is null or if any SAXException is thrown during
479    *           marshaling
480    * @throws org.exolab.castor.xml.ValidationException
481    *           if this object is an invalid instance according to the schema
482    */
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);
487   }
488
489   /**
490    * 
491    * 
492    * @param handler
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
499    *           marshaling
500    */
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);
505   }
506
507   /**
508      */
509   public void removeAllProperty() {
510     this._propertyList.clear();
511   }
512
513   /**
514    * Method removeProperty.
515    * 
516    * @param vProperty
517    * @return true if the object was removed from the collection.
518    */
519   public boolean removeProperty(
520       final uk.ac.vamsas.objects.core.Property vProperty) {
521     boolean removed = _propertyList.remove(vProperty);
522     return removed;
523   }
524
525   /**
526    * Method removePropertyAt.
527    * 
528    * @param index
529    * @return the element removed from the collection
530    */
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;
534   }
535
536   /**
537    * Sets the value of field 'description'.
538    * 
539    * @param description
540    *          the value of field 'description'.
541    */
542   public void setDescription(final java.lang.String description) {
543     this._description = description;
544   }
545
546   /**
547    * Sets the value of field 'end'.
548    * 
549    * @param end
550    *          the value of field 'end'.
551    */
552   public void setEnd(final long end) {
553     this._end = end;
554     this._has_end = true;
555   }
556
557   /**
558    * Sets the value of field 'name'.
559    * 
560    * @param name
561    *          the value of field 'name'.
562    */
563   public void setName(final java.lang.String name) {
564     this._name = name;
565   }
566
567   /**
568    * 
569    * 
570    * @param index
571    * @param vProperty
572    * @throws java.lang.IndexOutOfBoundsException
573    *           if the index given is outside the bounds of the collection
574    */
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) + "]");
582     }
583
584     this._propertyList.set(index, vProperty);
585   }
586
587   /**
588    * 
589    * 
590    * @param vPropertyArray
591    */
592   public void setProperty(
593       final uk.ac.vamsas.objects.core.Property[] vPropertyArray) {
594     // -- copy array
595     _propertyList.clear();
596
597     for (int i = 0; i < vPropertyArray.length; i++) {
598       this._propertyList.add(vPropertyArray[i]);
599     }
600   }
601
602   /**
603    * Sets the value of '_propertyList' by copying the given Vector. All elements
604    * will be checked for type safety.
605    * 
606    * @param vPropertyList
607    *          the Vector to copy.
608    */
609   public void setProperty(final java.util.Vector vPropertyList) {
610     // copy vector
611     this._propertyList.clear();
612
613     this._propertyList.addAll(vPropertyList);
614   }
615
616   /**
617    * Sets the value of '_propertyList' by setting it to the given Vector. No
618    * type checking is performed.
619    * 
620    * @deprecated
621    * 
622    * @param propertyVector
623    *          the Vector to set.
624    */
625   public void setPropertyAsReference(final java.util.Vector propertyVector) {
626     this._propertyList = propertyVector;
627   }
628
629   /**
630    * Sets the value of field 'sequence'.
631    * 
632    * @param sequence
633    *          the value of field 'sequence'.
634    */
635   public void setSequence(final java.lang.String sequence) {
636     this._sequence = sequence;
637   }
638
639   /**
640    * Sets the value of field 'start'.
641    * 
642    * @param start
643    *          the value of field 'start'.
644    */
645   public void setStart(final long start) {
646     this._start = start;
647     this._has_start = true;
648   }
649
650   /**
651    * Method unmarshal.
652    * 
653    * @param reader
654    * @throws org.exolab.castor.xml.MarshalException
655    *           if object is null or if any SAXException is thrown during
656    *           marshaling
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
660    */
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);
667   }
668
669   /**
670    * 
671    * 
672    * @throws org.exolab.castor.xml.ValidationException
673    *           if this object is an invalid instance according to the schema
674    */
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);
678   }
679
680 }