applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / core / Seg.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  * a region from start to end, with flag for inclusivity of terminii\r
33  * \r
34  * @version $Revision$ $Date$\r
35  */\r
36 public class Seg 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    * Field _start.\r
45    */\r
46   private int _start;\r
47 \r
48   /**\r
49    * keeps track of state for field: _start\r
50    */\r
51   private boolean _has_start;\r
52 \r
53   /**\r
54    * Field _end.\r
55    */\r
56   private int _end;\r
57 \r
58   /**\r
59    * keeps track of state for field: _end\r
60    */\r
61   private boolean _has_end;\r
62 \r
63   /**\r
64    * when false, a consecutive range like 'start=1, end=2' means the region\r
65    * lying after position 1 and before position 2\r
66    * \r
67    */\r
68   private boolean _inclusive;\r
69 \r
70   /**\r
71    * keeps track of state for field: _inclusive\r
72    */\r
73   private boolean _has_inclusive;\r
74 \r
75   // ----------------/\r
76   // - Constructors -/\r
77   // ----------------/\r
78 \r
79   public Seg() {\r
80     super();\r
81   }\r
82 \r
83   // -----------/\r
84   // - Methods -/\r
85   // -----------/\r
86 \r
87   /**\r
88      */\r
89   public void deleteEnd() {\r
90     this._has_end = false;\r
91   }\r
92 \r
93   /**\r
94      */\r
95   public void deleteInclusive() {\r
96     this._has_inclusive = false;\r
97   }\r
98 \r
99   /**\r
100      */\r
101   public void deleteStart() {\r
102     this._has_start = false;\r
103   }\r
104 \r
105   /**\r
106    * Overrides the java.lang.Object.equals method.\r
107    * \r
108    * @param obj\r
109    * @return true if the objects are equal.\r
110    */\r
111   public boolean equals(final java.lang.Object obj) {\r
112     if (this == obj)\r
113       return true;\r
114 \r
115     if (super.equals(obj) == false)\r
116       return false;\r
117 \r
118     if (obj instanceof Seg) {\r
119 \r
120       Seg temp = (Seg) obj;\r
121       boolean thcycle;\r
122       boolean tmcycle;\r
123       if (this._start != temp._start)\r
124         return false;\r
125       if (this._has_start != temp._has_start)\r
126         return false;\r
127       if (this._end != temp._end)\r
128         return false;\r
129       if (this._has_end != temp._has_end)\r
130         return false;\r
131       if (this._inclusive != temp._inclusive)\r
132         return false;\r
133       if (this._has_inclusive != temp._has_inclusive)\r
134         return false;\r
135       return true;\r
136     }\r
137     return false;\r
138   }\r
139 \r
140   /**\r
141    * Returns the value of field 'end'.\r
142    * \r
143    * @return the value of field 'End'.\r
144    */\r
145   public int getEnd() {\r
146     return this._end;\r
147   }\r
148 \r
149   /**\r
150    * Returns the value of field 'inclusive'. The field 'inclusive' has the\r
151    * following description: when false, a consecutive range like 'start=1,\r
152    * end=2' means the region lying after position 1 and before position 2\r
153    * \r
154    * \r
155    * @return the value of field 'Inclusive'.\r
156    */\r
157   public boolean getInclusive() {\r
158     return this._inclusive;\r
159   }\r
160 \r
161   /**\r
162    * Returns the value of field 'start'.\r
163    * \r
164    * @return the value of field 'Start'.\r
165    */\r
166   public int getStart() {\r
167     return this._start;\r
168   }\r
169 \r
170   /**\r
171    * Method hasEnd.\r
172    * \r
173    * @return true if at least one End has been added\r
174    */\r
175   public boolean hasEnd() {\r
176     return this._has_end;\r
177   }\r
178 \r
179   /**\r
180    * Method hasInclusive.\r
181    * \r
182    * @return true if at least one Inclusive has been added\r
183    */\r
184   public boolean hasInclusive() {\r
185     return this._has_inclusive;\r
186   }\r
187 \r
188   /**\r
189    * Method hasStart.\r
190    * \r
191    * @return true if at least one Start has been added\r
192    */\r
193   public boolean hasStart() {\r
194     return this._has_start;\r
195   }\r
196 \r
197   /**\r
198    * Overrides the java.lang.Object.hashCode method.\r
199    * <p>\r
200    * The following steps came from <b>Effective Java Programming Language\r
201    * Guide</b> by Joshua Bloch, Chapter 3\r
202    * \r
203    * @return a hash code value for the object.\r
204    */\r
205   public int hashCode() {\r
206     int result = super.hashCode();\r
207 \r
208     long tmp;\r
209     result = 37 * result + _start;\r
210     result = 37 * result + _end;\r
211     result = 37 * result + (_inclusive ? 0 : 1);\r
212 \r
213     return result;\r
214   }\r
215 \r
216   /**\r
217    * Returns the value of field 'inclusive'. The field 'inclusive' has the\r
218    * following description: when false, a consecutive range like 'start=1,\r
219    * end=2' means the region lying after position 1 and before position 2\r
220    * \r
221    * \r
222    * @return the value of field 'Inclusive'.\r
223    */\r
224   public boolean isInclusive() {\r
225     return this._inclusive;\r
226   }\r
227 \r
228   /**\r
229    * Method isValid.\r
230    * \r
231    * @return true if this object is valid according to the schema\r
232    */\r
233   public boolean isValid() {\r
234     try {\r
235       validate();\r
236     } catch (org.exolab.castor.xml.ValidationException vex) {\r
237       return false;\r
238     }\r
239     return true;\r
240   }\r
241 \r
242   /**\r
243    * \r
244    * \r
245    * @param out\r
246    * @throws org.exolab.castor.xml.MarshalException\r
247    *           if object is null or if any SAXException is thrown during\r
248    *           marshaling\r
249    * @throws org.exolab.castor.xml.ValidationException\r
250    *           if this object is an invalid instance according to the schema\r
251    */\r
252   public void marshal(final java.io.Writer out)\r
253       throws org.exolab.castor.xml.MarshalException,\r
254       org.exolab.castor.xml.ValidationException {\r
255     Marshaller.marshal(this, out);\r
256   }\r
257 \r
258   /**\r
259    * \r
260    * \r
261    * @param handler\r
262    * @throws java.io.IOException\r
263    *           if an IOException occurs during marshaling\r
264    * @throws org.exolab.castor.xml.ValidationException\r
265    *           if this object is an invalid instance according to the schema\r
266    * @throws org.exolab.castor.xml.MarshalException\r
267    *           if object is null or if any SAXException is thrown during\r
268    *           marshaling\r
269    */\r
270   public void marshal(final org.xml.sax.ContentHandler handler)\r
271       throws java.io.IOException, org.exolab.castor.xml.MarshalException,\r
272       org.exolab.castor.xml.ValidationException {\r
273     Marshaller.marshal(this, handler);\r
274   }\r
275 \r
276   /**\r
277    * Sets the value of field 'end'.\r
278    * \r
279    * @param end\r
280    *          the value of field 'end'.\r
281    */\r
282   public void setEnd(final int end) {\r
283     this._end = end;\r
284     this._has_end = true;\r
285   }\r
286 \r
287   /**\r
288    * Sets the value of field 'inclusive'. The field 'inclusive' has the\r
289    * following description: when false, a consecutive range like 'start=1,\r
290    * end=2' means the region lying after position 1 and before position 2\r
291    * \r
292    * \r
293    * @param inclusive\r
294    *          the value of field 'inclusive'.\r
295    */\r
296   public void setInclusive(final boolean inclusive) {\r
297     this._inclusive = inclusive;\r
298     this._has_inclusive = true;\r
299   }\r
300 \r
301   /**\r
302    * Sets the value of field 'start'.\r
303    * \r
304    * @param start\r
305    *          the value of field 'start'.\r
306    */\r
307   public void setStart(final int start) {\r
308     this._start = start;\r
309     this._has_start = true;\r
310   }\r
311 \r
312   /**\r
313    * Method unmarshal.\r
314    * \r
315    * @param reader\r
316    * @throws org.exolab.castor.xml.MarshalException\r
317    *           if object is null or if any SAXException is thrown during\r
318    *           marshaling\r
319    * @throws org.exolab.castor.xml.ValidationException\r
320    *           if this object is an invalid instance according to the schema\r
321    * @return the unmarshaled uk.ac.vamsas.objects.core.Seg\r
322    */\r
323   public static uk.ac.vamsas.objects.core.Seg unmarshal(\r
324       final java.io.Reader reader)\r
325       throws org.exolab.castor.xml.MarshalException,\r
326       org.exolab.castor.xml.ValidationException {\r
327     return (uk.ac.vamsas.objects.core.Seg) Unmarshaller.unmarshal(\r
328         uk.ac.vamsas.objects.core.Seg.class, reader);\r
329   }\r
330 \r
331   /**\r
332    * \r
333    * \r
334    * @throws org.exolab.castor.xml.ValidationException\r
335    *           if this object is an invalid instance according to the schema\r
336    */\r
337   public void validate() throws org.exolab.castor.xml.ValidationException {\r
338     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();\r
339     validator.validate(this);\r
340   }\r
341 \r
342 }\r