applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / core / Newick.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 Newick.
33  * 
34  * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
35  *          $
36  */
37 public class Newick extends uk.ac.vamsas.client.Vobject implements
38     java.io.Serializable {
39
40   // --------------------------/
41   // - Class/Member Variables -/
42   // --------------------------/
43
44   /**
45    * internal content storage
46    */
47   private java.lang.String _content = "";
48
49   /**
50    * Field _title.
51    */
52   private java.lang.String _title;
53
54   /**
55    * Primary Key for vamsas object referencing
56    * 
57    */
58   private java.lang.String _id;
59
60   /**
61    * Field _modifiable.
62    */
63   private java.lang.String _modifiable;
64
65   // ----------------/
66   // - Constructors -/
67   // ----------------/
68
69   public Newick() {
70     super();
71     setContent("");
72   }
73
74   // -----------/
75   // - Methods -/
76   // -----------/
77
78   /**
79    * Overrides the java.lang.Object.equals method.
80    * 
81    * @param obj
82    * @return true if the objects are equal.
83    */
84   public boolean equals(final java.lang.Object obj) {
85     if (this == obj)
86       return true;
87
88     if (super.equals(obj) == false)
89       return false;
90
91     if (obj instanceof Newick) {
92
93       Newick temp = (Newick) obj;
94       boolean thcycle;
95       boolean tmcycle;
96       if (this._content != null) {
97         if (temp._content == null)
98           return false;
99         if (this._content != temp._content) {
100           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._content);
101           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._content);
102           if (thcycle != tmcycle) {
103             if (!thcycle) {
104               org.castor.util.CycleBreaker.releaseCycleHandle(this._content);
105             }
106             ;
107             if (!tmcycle) {
108               org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);
109             }
110             ;
111             return false;
112           }
113           if (!thcycle) {
114             if (!this._content.equals(temp._content)) {
115               org.castor.util.CycleBreaker.releaseCycleHandle(this._content);
116               org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);
117               return false;
118             }
119             org.castor.util.CycleBreaker.releaseCycleHandle(this._content);
120             org.castor.util.CycleBreaker.releaseCycleHandle(temp._content);
121           }
122         }
123       } else if (temp._content != null)
124         return false;
125       if (this._title != null) {
126         if (temp._title == null)
127           return false;
128         if (this._title != temp._title) {
129           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._title);
130           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._title);
131           if (thcycle != tmcycle) {
132             if (!thcycle) {
133               org.castor.util.CycleBreaker.releaseCycleHandle(this._title);
134             }
135             ;
136             if (!tmcycle) {
137               org.castor.util.CycleBreaker.releaseCycleHandle(temp._title);
138             }
139             ;
140             return false;
141           }
142           if (!thcycle) {
143             if (!this._title.equals(temp._title)) {
144               org.castor.util.CycleBreaker.releaseCycleHandle(this._title);
145               org.castor.util.CycleBreaker.releaseCycleHandle(temp._title);
146               return false;
147             }
148             org.castor.util.CycleBreaker.releaseCycleHandle(this._title);
149             org.castor.util.CycleBreaker.releaseCycleHandle(temp._title);
150           }
151         }
152       } else if (temp._title != null)
153         return false;
154       if (this._id != null) {
155         if (temp._id == null)
156           return false;
157         if (this._id != temp._id) {
158           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._id);
159           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._id);
160           if (thcycle != tmcycle) {
161             if (!thcycle) {
162               org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
163             }
164             ;
165             if (!tmcycle) {
166               org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
167             }
168             ;
169             return false;
170           }
171           if (!thcycle) {
172             if (!this._id.equals(temp._id)) {
173               org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
174               org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
175               return false;
176             }
177             org.castor.util.CycleBreaker.releaseCycleHandle(this._id);
178             org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);
179           }
180         }
181       } else if (temp._id != null)
182         return false;
183       if (this._modifiable != null) {
184         if (temp._modifiable == null)
185           return false;
186         if (this._modifiable != temp._modifiable) {
187           thcycle = org.castor.util.CycleBreaker
188               .startingToCycle(this._modifiable);
189           tmcycle = org.castor.util.CycleBreaker
190               .startingToCycle(temp._modifiable);
191           if (thcycle != tmcycle) {
192             if (!thcycle) {
193               org.castor.util.CycleBreaker.releaseCycleHandle(this._modifiable);
194             }
195             ;
196             if (!tmcycle) {
197               org.castor.util.CycleBreaker.releaseCycleHandle(temp._modifiable);
198             }
199             ;
200             return false;
201           }
202           if (!thcycle) {
203             if (!this._modifiable.equals(temp._modifiable)) {
204               org.castor.util.CycleBreaker.releaseCycleHandle(this._modifiable);
205               org.castor.util.CycleBreaker.releaseCycleHandle(temp._modifiable);
206               return false;
207             }
208             org.castor.util.CycleBreaker.releaseCycleHandle(this._modifiable);
209             org.castor.util.CycleBreaker.releaseCycleHandle(temp._modifiable);
210           }
211         }
212       } else if (temp._modifiable != null)
213         return false;
214       return true;
215     }
216     return false;
217   }
218
219   /**
220    * Returns the value of field 'content'. The field 'content' has the following
221    * description: internal content storage
222    * 
223    * @return the value of field 'Content'.
224    */
225   public java.lang.String getContent() {
226     return this._content;
227   }
228
229   /**
230    * Returns the value of field 'id'. The field 'id' has the following
231    * description: Primary Key for vamsas object referencing
232    * 
233    * 
234    * @return the value of field 'Id'.
235    */
236   public java.lang.String getId() {
237     return this._id;
238   }
239
240   /**
241    * Returns the value of field 'modifiable'.
242    * 
243    * @return the value of field 'Modifiable'.
244    */
245   public java.lang.String getModifiable() {
246     return this._modifiable;
247   }
248
249   /**
250    * Returns the value of field 'title'.
251    * 
252    * @return the value of field 'Title'.
253    */
254   public java.lang.String getTitle() {
255     return this._title;
256   }
257
258   /**
259    * Overrides the java.lang.Object.hashCode method.
260    * <p>
261    * The following steps came from <b>Effective Java Programming Language
262    * Guide</b> by Joshua Bloch, Chapter 3
263    * 
264    * @return a hash code value for the object.
265    */
266   public int hashCode() {
267     int result = super.hashCode();
268
269     long tmp;
270     if (_content != null
271         && !org.castor.util.CycleBreaker.startingToCycle(_content)) {
272       result = 37 * result + _content.hashCode();
273       org.castor.util.CycleBreaker.releaseCycleHandle(_content);
274     }
275     if (_title != null && !org.castor.util.CycleBreaker.startingToCycle(_title)) {
276       result = 37 * result + _title.hashCode();
277       org.castor.util.CycleBreaker.releaseCycleHandle(_title);
278     }
279     if (_id != null && !org.castor.util.CycleBreaker.startingToCycle(_id)) {
280       result = 37 * result + _id.hashCode();
281       org.castor.util.CycleBreaker.releaseCycleHandle(_id);
282     }
283     if (_modifiable != null
284         && !org.castor.util.CycleBreaker.startingToCycle(_modifiable)) {
285       result = 37 * result + _modifiable.hashCode();
286       org.castor.util.CycleBreaker.releaseCycleHandle(_modifiable);
287     }
288
289     return result;
290   }
291
292   /**
293    * Method isValid.
294    * 
295    * @return true if this object is valid according to the schema
296    */
297   public boolean isValid() {
298     try {
299       validate();
300     } catch (org.exolab.castor.xml.ValidationException vex) {
301       return false;
302     }
303     return true;
304   }
305
306   /**
307    * 
308    * 
309    * @param out
310    * @throws org.exolab.castor.xml.MarshalException
311    *           if object is null or if any SAXException is thrown during
312    *           marshaling
313    * @throws org.exolab.castor.xml.ValidationException
314    *           if this object is an invalid instance according to the schema
315    */
316   public void marshal(final java.io.Writer out)
317       throws org.exolab.castor.xml.MarshalException,
318       org.exolab.castor.xml.ValidationException {
319     Marshaller.marshal(this, out);
320   }
321
322   /**
323    * 
324    * 
325    * @param handler
326    * @throws java.io.IOException
327    *           if an IOException occurs during marshaling
328    * @throws org.exolab.castor.xml.ValidationException
329    *           if this object is an invalid instance according to the schema
330    * @throws org.exolab.castor.xml.MarshalException
331    *           if object is null or if any SAXException is thrown during
332    *           marshaling
333    */
334   public void marshal(final org.xml.sax.ContentHandler handler)
335       throws java.io.IOException, org.exolab.castor.xml.MarshalException,
336       org.exolab.castor.xml.ValidationException {
337     Marshaller.marshal(this, handler);
338   }
339
340   /**
341    * Sets the value of field 'content'. The field 'content' has the following
342    * description: internal content storage
343    * 
344    * @param content
345    *          the value of field 'content'.
346    */
347   public void setContent(final java.lang.String content) {
348     this._content = content;
349   }
350
351   /**
352    * Sets the value of field 'id'. The field 'id' has the following description:
353    * Primary Key for vamsas object referencing
354    * 
355    * 
356    * @param id
357    *          the value of field 'id'.
358    */
359   public void setId(final java.lang.String id) {
360     this._id = id;
361   }
362
363   /**
364    * Sets the value of field 'modifiable'.
365    * 
366    * @param modifiable
367    *          the value of field 'modifiable'.
368    */
369   public void setModifiable(final java.lang.String modifiable) {
370     this._modifiable = modifiable;
371   }
372
373   /**
374    * Sets the value of field 'title'.
375    * 
376    * @param title
377    *          the value of field 'title'.
378    */
379   public void setTitle(final java.lang.String title) {
380     this._title = title;
381   }
382
383   /**
384    * Method unmarshal.
385    * 
386    * @param reader
387    * @throws org.exolab.castor.xml.MarshalException
388    *           if object is null or if any SAXException is thrown during
389    *           marshaling
390    * @throws org.exolab.castor.xml.ValidationException
391    *           if this object is an invalid instance according to the schema
392    * @return the unmarshaled uk.ac.vamsas.objects.core.Newick
393    */
394   public static uk.ac.vamsas.objects.core.Newick unmarshal(
395       final java.io.Reader reader)
396       throws org.exolab.castor.xml.MarshalException,
397       org.exolab.castor.xml.ValidationException {
398     return (uk.ac.vamsas.objects.core.Newick) Unmarshaller.unmarshal(
399         uk.ac.vamsas.objects.core.Newick.class, reader);
400   }
401
402   /**
403    * 
404    * 
405    * @throws org.exolab.castor.xml.ValidationException
406    *           if this object is an invalid instance according to the schema
407    */
408   public void validate() throws org.exolab.castor.xml.ValidationException {
409     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
410     validator.validate(this);
411   }
412
413 }