applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / core / Map.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  * the local mapType maps from the parent sequence coordinate frame to the\r
33  * reference frame defined by the dbRef element. The mapped mapType is the\r
34  * mapped range defined on the dbRef element's reference frame. Conventionally,\r
35  * the unit attribute defaults to 1, or will be inferred from the local\r
36  * sequence's dictionary type and any dictionary type associated with the\r
37  * database being mapped to. However, it may be used to avoid ambiguity.\r
38  * \r
39  * \r
40  * @version $Revision$ $Date$\r
41  */\r
42 public class Map extends uk.ac.vamsas.objects.core.MapType implements\r
43     java.io.Serializable {\r
44 \r
45   // --------------------------/\r
46   // - Class/Member Variables -/\r
47   // --------------------------/\r
48 \r
49   /**\r
50    * Field _id.\r
51    */\r
52   private java.lang.String _id;\r
53 \r
54   // ----------------/\r
55   // - Constructors -/\r
56   // ----------------/\r
57 \r
58   public Map() {\r
59     super();\r
60   }\r
61 \r
62   // -----------/\r
63   // - Methods -/\r
64   // -----------/\r
65 \r
66   /**\r
67    * Overrides the java.lang.Object.equals method.\r
68    * \r
69    * @param obj\r
70    * @return true if the objects are equal.\r
71    */\r
72   public boolean equals(final java.lang.Object obj) {\r
73     if (this == obj)\r
74       return true;\r
75 \r
76     if (super.equals(obj) == false)\r
77       return false;\r
78 \r
79     if (obj instanceof Map) {\r
80 \r
81       Map temp = (Map) obj;\r
82       boolean thcycle;\r
83       boolean tmcycle;\r
84       if (this._id != null) {\r
85         if (temp._id == null)\r
86           return false;\r
87         if (this._id != temp._id) {\r
88           thcycle = org.castor.util.CycleBreaker.startingToCycle(this._id);\r
89           tmcycle = org.castor.util.CycleBreaker.startingToCycle(temp._id);\r
90           if (thcycle != tmcycle) {\r
91             if (!thcycle) {\r
92               org.castor.util.CycleBreaker.releaseCycleHandle(this._id);\r
93             }\r
94             ;\r
95             if (!tmcycle) {\r
96               org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);\r
97             }\r
98             ;\r
99             return false;\r
100           }\r
101           if (!thcycle) {\r
102             if (!this._id.equals(temp._id)) {\r
103               org.castor.util.CycleBreaker.releaseCycleHandle(this._id);\r
104               org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);\r
105               return false;\r
106             }\r
107             org.castor.util.CycleBreaker.releaseCycleHandle(this._id);\r
108             org.castor.util.CycleBreaker.releaseCycleHandle(temp._id);\r
109           }\r
110         }\r
111       } else if (temp._id != null)\r
112         return false;\r
113       return true;\r
114     }\r
115     return false;\r
116   }\r
117 \r
118   /**\r
119    * Returns the value of field 'id'.\r
120    * \r
121    * @return the value of field 'Id'.\r
122    */\r
123   public java.lang.String getId() {\r
124     return this._id;\r
125   }\r
126 \r
127   /**\r
128    * Overrides the java.lang.Object.hashCode method.\r
129    * <p>\r
130    * The following steps came from <b>Effective Java Programming Language\r
131    * Guide</b> by Joshua Bloch, Chapter 3\r
132    * \r
133    * @return a hash code value for the object.\r
134    */\r
135   public int hashCode() {\r
136     int result = super.hashCode();\r
137 \r
138     long tmp;\r
139     if (_id != null && !org.castor.util.CycleBreaker.startingToCycle(_id)) {\r
140       result = 37 * result + _id.hashCode();\r
141       org.castor.util.CycleBreaker.releaseCycleHandle(_id);\r
142     }\r
143 \r
144     return result;\r
145   }\r
146 \r
147   /**\r
148    * Method isValid.\r
149    * \r
150    * @return true if this object is valid according to the schema\r
151    */\r
152   public boolean isValid() {\r
153     try {\r
154       validate();\r
155     } catch (org.exolab.castor.xml.ValidationException vex) {\r
156       return false;\r
157     }\r
158     return true;\r
159   }\r
160 \r
161   /**\r
162    * \r
163    * \r
164    * @param out\r
165    * @throws org.exolab.castor.xml.MarshalException\r
166    *           if object is null or if any SAXException is thrown during\r
167    *           marshaling\r
168    * @throws org.exolab.castor.xml.ValidationException\r
169    *           if this object is an invalid instance according to the schema\r
170    */\r
171   public void marshal(final java.io.Writer out)\r
172       throws org.exolab.castor.xml.MarshalException,\r
173       org.exolab.castor.xml.ValidationException {\r
174     Marshaller.marshal(this, out);\r
175   }\r
176 \r
177   /**\r
178    * \r
179    * \r
180    * @param handler\r
181    * @throws java.io.IOException\r
182    *           if an IOException occurs during marshaling\r
183    * @throws org.exolab.castor.xml.ValidationException\r
184    *           if this object is an invalid instance according to the schema\r
185    * @throws org.exolab.castor.xml.MarshalException\r
186    *           if object is null or if any SAXException is thrown during\r
187    *           marshaling\r
188    */\r
189   public void marshal(final org.xml.sax.ContentHandler handler)\r
190       throws java.io.IOException, org.exolab.castor.xml.MarshalException,\r
191       org.exolab.castor.xml.ValidationException {\r
192     Marshaller.marshal(this, handler);\r
193   }\r
194 \r
195   /**\r
196    * Sets the value of field 'id'.\r
197    * \r
198    * @param id\r
199    *          the value of field 'id'.\r
200    */\r
201   public void setId(final java.lang.String id) {\r
202     this._id = id;\r
203   }\r
204 \r
205   /**\r
206    * Method unmarshal.\r
207    * \r
208    * @param reader\r
209    * @throws org.exolab.castor.xml.MarshalException\r
210    *           if object is null or if any SAXException is thrown during\r
211    *           marshaling\r
212    * @throws org.exolab.castor.xml.ValidationException\r
213    *           if this object is an invalid instance according to the schema\r
214    * @return the unmarshaled uk.ac.vamsas.objects.core.MapType\r
215    */\r
216   public static uk.ac.vamsas.objects.core.MapType unmarshal(\r
217       final java.io.Reader reader)\r
218       throws org.exolab.castor.xml.MarshalException,\r
219       org.exolab.castor.xml.ValidationException {\r
220     return (uk.ac.vamsas.objects.core.MapType) Unmarshaller.unmarshal(\r
221         uk.ac.vamsas.objects.core.Map.class, reader);\r
222   }\r
223 \r
224   /**\r
225    * \r
226    * \r
227    * @throws org.exolab.castor.xml.ValidationException\r
228    *           if this object is an invalid instance according to the schema\r
229    */\r
230   public void validate() throws org.exolab.castor.xml.ValidationException {\r
231     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
232     validator.validate(this);\r
233   }\r
234 \r
235 }\r