applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / core / MapType.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  * Two sets of ranges defined between objects - usually sequences, indicating\r
33  * which regions on each are mapped.\r
34  * \r
35  * @version $Revision$ $Date$\r
36  */\r
37 public class MapType extends uk.ac.vamsas.client.Vobject implements\r
38     java.io.Serializable {\r
39 \r
40   // --------------------------/\r
41   // - Class/Member Variables -/\r
42   // --------------------------/\r
43 \r
44   /**\r
45      */\r
46   private uk.ac.vamsas.objects.core.Local _local;\r
47 \r
48   /**\r
49      */\r
50   private uk.ac.vamsas.objects.core.Mapped _mapped;\r
51 \r
52   // ----------------/\r
53   // - Constructors -/\r
54   // ----------------/\r
55 \r
56   public MapType() {\r
57     super();\r
58   }\r
59 \r
60   // -----------/\r
61   // - Methods -/\r
62   // -----------/\r
63 \r
64   /**\r
65    * Overrides the java.lang.Object.equals method.\r
66    * \r
67    * @param obj\r
68    * @return true if the objects are equal.\r
69    */\r
70   public boolean equals(final java.lang.Object obj) {\r
71     if (this == obj)\r
72       return true;\r
73 \r
74     if (super.equals(obj) == false)\r
75       return false;\r
76 \r
77     if (obj instanceof MapType) {\r
78 \r
79       MapType temp = (MapType) obj;\r
80       boolean thcycle;\r
81       boolean tmcycle;\r
82       if (this._local != null) {\r
83         if (temp._local == null)\r
84           return false;\r
85         if (this._local != temp._local) {\r
86           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._local);\r
87           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._local);\r
88           if (thcycle != tmcycle) {\r
89             if (!thcycle) {\r
90               org.castor.util.CycleBreaker.releaseCycleHandle(this._local);\r
91             }\r
92             ;\r
93             if (!tmcycle) {\r
94               org.castor.util.CycleBreaker.releaseCycleHandle(temp._local);\r
95             }\r
96             ;\r
97             return false;\r
98           }\r
99           if (!thcycle) {\r
100             if (!this._local.equals(temp._local)) {\r
101               org.castor.util.CycleBreaker.releaseCycleHandle(this._local);\r
102               org.castor.util.CycleBreaker.releaseCycleHandle(temp._local);\r
103               return false;\r
104             }\r
105             org.castor.util.CycleBreaker.releaseCycleHandle(this._local);\r
106             org.castor.util.CycleBreaker.releaseCycleHandle(temp._local);\r
107           }\r
108         }\r
109       } else if (temp._local != null)\r
110         return false;\r
111       if (this._mapped != null) {\r
112         if (temp._mapped == null)\r
113           return false;\r
114         if (this._mapped != temp._mapped) {\r
115           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._mapped);\r
116           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._mapped);\r
117           if (thcycle != tmcycle) {\r
118             if (!thcycle) {\r
119               org.castor.util.CycleBreaker.releaseCycleHandle(this._mapped);\r
120             }\r
121             ;\r
122             if (!tmcycle) {\r
123               org.castor.util.CycleBreaker.releaseCycleHandle(temp._mapped);\r
124             }\r
125             ;\r
126             return false;\r
127           }\r
128           if (!thcycle) {\r
129             if (!this._mapped.equals(temp._mapped)) {\r
130               org.castor.util.CycleBreaker.releaseCycleHandle(this._mapped);\r
131               org.castor.util.CycleBreaker.releaseCycleHandle(temp._mapped);\r
132               return false;\r
133             }\r
134             org.castor.util.CycleBreaker.releaseCycleHandle(this._mapped);\r
135             org.castor.util.CycleBreaker.releaseCycleHandle(temp._mapped);\r
136           }\r
137         }\r
138       } else if (temp._mapped != null)\r
139         return false;\r
140       return true;\r
141     }\r
142     return false;\r
143   }\r
144 \r
145   /**\r
146    * Returns the value of field 'local'.\r
147    * \r
148    * @return the value of field 'Local'.\r
149    */\r
150   public uk.ac.vamsas.objects.core.Local getLocal() {\r
151     return this._local;\r
152   }\r
153 \r
154   /**\r
155    * Returns the value of field 'mapped'.\r
156    * \r
157    * @return the value of field 'Mapped'.\r
158    */\r
159   public uk.ac.vamsas.objects.core.Mapped getMapped() {\r
160     return this._mapped;\r
161   }\r
162 \r
163   /**\r
164    * Overrides the java.lang.Object.hashCode method.\r
165    * <p>\r
166    * The following steps came from <b>Effective Java Programming Language\r
167    * Guide</b> by Joshua Bloch, Chapter 3\r
168    * \r
169    * @return a hash code value for the object.\r
170    */\r
171   public int hashCode() {\r
172     int result = super.hashCode();\r
173 \r
174     long tmp;\r
175     if (_local != null && !org.castor.util.CycleBreaker.startingToCycle(_local)) {\r
176       result = 37 * result + _local.hashCode();\r
177       org.castor.util.CycleBreaker.releaseCycleHandle(_local);\r
178     }\r
179     if (_mapped != null\r
180         && !org.castor.util.CycleBreaker.startingToCycle(_mapped)) {\r
181       result = 37 * result + _mapped.hashCode();\r
182       org.castor.util.CycleBreaker.releaseCycleHandle(_mapped);\r
183     }\r
184 \r
185     return result;\r
186   }\r
187 \r
188   /**\r
189    * Method isValid.\r
190    * \r
191    * @return true if this object is valid according to the schema\r
192    */\r
193   public boolean isValid() {\r
194     try {\r
195       validate();\r
196     } catch (org.exolab.castor.xml.ValidationException vex) {\r
197       return false;\r
198     }\r
199     return true;\r
200   }\r
201 \r
202   /**\r
203    * \r
204    * \r
205    * @param out\r
206    * @throws org.exolab.castor.xml.MarshalException\r
207    *           if object is null or if any SAXException is thrown during\r
208    *           marshaling\r
209    * @throws org.exolab.castor.xml.ValidationException\r
210    *           if this object is an invalid instance according to the schema\r
211    */\r
212   public void marshal(final java.io.Writer out)\r
213       throws org.exolab.castor.xml.MarshalException,\r
214       org.exolab.castor.xml.ValidationException {\r
215     Marshaller.marshal(this, out);\r
216   }\r
217 \r
218   /**\r
219    * \r
220    * \r
221    * @param handler\r
222    * @throws java.io.IOException\r
223    *           if an IOException occurs during marshaling\r
224    * @throws org.exolab.castor.xml.ValidationException\r
225    *           if this object is an invalid instance according to the schema\r
226    * @throws org.exolab.castor.xml.MarshalException\r
227    *           if object is null or if any SAXException is thrown during\r
228    *           marshaling\r
229    */\r
230   public void marshal(final org.xml.sax.ContentHandler handler)\r
231       throws java.io.IOException, org.exolab.castor.xml.MarshalException,\r
232       org.exolab.castor.xml.ValidationException {\r
233     Marshaller.marshal(this, handler);\r
234   }\r
235 \r
236   /**\r
237    * Sets the value of field 'local'.\r
238    * \r
239    * @param local\r
240    *          the value of field 'local'.\r
241    */\r
242   public void setLocal(final uk.ac.vamsas.objects.core.Local local) {\r
243     this._local = local;\r
244   }\r
245 \r
246   /**\r
247    * Sets the value of field 'mapped'.\r
248    * \r
249    * @param mapped\r
250    *          the value of field 'mapped'.\r
251    */\r
252   public void setMapped(final uk.ac.vamsas.objects.core.Mapped mapped) {\r
253     this._mapped = mapped;\r
254   }\r
255 \r
256   /**\r
257    * Method unmarshal.\r
258    * \r
259    * @param reader\r
260    * @throws org.exolab.castor.xml.MarshalException\r
261    *           if object is null or if any SAXException is thrown during\r
262    *           marshaling\r
263    * @throws org.exolab.castor.xml.ValidationException\r
264    *           if this object is an invalid instance according to the schema\r
265    * @return the unmarshaled uk.ac.vamsas.objects.core.MapType\r
266    */\r
267   public static uk.ac.vamsas.objects.core.MapType unmarshal(\r
268       final java.io.Reader reader)\r
269       throws org.exolab.castor.xml.MarshalException,\r
270       org.exolab.castor.xml.ValidationException {\r
271     return (uk.ac.vamsas.objects.core.MapType) Unmarshaller.unmarshal(\r
272         uk.ac.vamsas.objects.core.MapType.class, reader);\r
273   }\r
274 \r
275   /**\r
276    * \r
277    * \r
278    * @throws org.exolab.castor.xml.ValidationException\r
279    *           if this object is an invalid instance according to the schema\r
280    */\r
281   public void validate() throws org.exolab.castor.xml.ValidationException {\r
282     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
283     validator.validate(this);\r
284   }\r
285 \r
286 }\r