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