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