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