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