applied LGPLv3 and source code formatting.
[vamsas.git] / src / uk / ac / vamsas / objects / core / User.java
1 /*
2  * This file is part of the Vamsas Client version 0.1. 
3  * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite, 
4  *  Andrew Waterhouse and Dominik Lindner.
5  * 
6  * Earlier versions have also been incorporated into Jalview version 2.4 
7  * since 2008, and TOPALi version 2 since 2007.
8  * 
9  * The Vamsas Client is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *  
14  * The Vamsas Client is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  * 
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with the Vamsas Client.  If not, see <http://www.gnu.org/licenses/>.
21  */
22 package uk.ac.vamsas.objects.core;
23
24 //---------------------------------/
25 //- Imported classes and packages -/
26 //---------------------------------/
27
28 import org.exolab.castor.xml.Marshaller;
29 import org.exolab.castor.xml.Unmarshaller;
30
31 /**
32  * Class User.
33  * 
34  * @version $Revision$ $Date: 2007-06-28 14:51:44 +0100 (Thu, 28 Jun 2007)
35  *          $
36  */
37 public class User extends uk.ac.vamsas.objects.core.AppData implements
38     java.io.Serializable {
39
40   // --------------------------/
41   // - Class/Member Variables -/
42   // --------------------------/
43
44   /**
45    * Field _fullname.
46    */
47   private java.lang.String _fullname;
48
49   /**
50    * Field _organization.
51    */
52   private java.lang.String _organization;
53
54   // ----------------/
55   // - Constructors -/
56   // ----------------/
57
58   public User() {
59     super();
60   }
61
62   // -----------/
63   // - Methods -/
64   // -----------/
65
66   /**
67    * Overrides the java.lang.Object.equals method.
68    * 
69    * @param obj
70    * @return true if the objects are equal.
71    */
72   public boolean equals(final java.lang.Object obj) {
73     if (this == obj)
74       return true;
75
76     if (super.equals(obj) == false)
77       return false;
78
79     if (obj instanceof User) {
80
81       User temp = (User) obj;
82       boolean thcycle;
83       boolean tmcycle;
84       if (this._fullname != null) {
85         if (temp._fullname == null)
86           return false;
87         if (this._fullname != temp._fullname) {
88           thcycle = org.castor.util.CycleBreaker
89               .startingToCycle(this._fullname);
90           tmcycle = org.castor.util.CycleBreaker
91               .startingToCycle(temp._fullname);
92           if (thcycle != tmcycle) {
93             if (!thcycle) {
94               org.castor.util.CycleBreaker.releaseCycleHandle(this._fullname);
95             }
96             ;
97             if (!tmcycle) {
98               org.castor.util.CycleBreaker.releaseCycleHandle(temp._fullname);
99             }
100             ;
101             return false;
102           }
103           if (!thcycle) {
104             if (!this._fullname.equals(temp._fullname)) {
105               org.castor.util.CycleBreaker.releaseCycleHandle(this._fullname);
106               org.castor.util.CycleBreaker.releaseCycleHandle(temp._fullname);
107               return false;
108             }
109             org.castor.util.CycleBreaker.releaseCycleHandle(this._fullname);
110             org.castor.util.CycleBreaker.releaseCycleHandle(temp._fullname);
111           }
112         }
113       } else if (temp._fullname != null)
114         return false;
115       if (this._organization != null) {
116         if (temp._organization == null)
117           return false;
118         if (this._organization != temp._organization) {
119           thcycle = org.castor.util.CycleBreaker
120               .startingToCycle(this._organization);
121           tmcycle = org.castor.util.CycleBreaker
122               .startingToCycle(temp._organization);
123           if (thcycle != tmcycle) {
124             if (!thcycle) {
125               org.castor.util.CycleBreaker
126                   .releaseCycleHandle(this._organization);
127             }
128             ;
129             if (!tmcycle) {
130               org.castor.util.CycleBreaker
131                   .releaseCycleHandle(temp._organization);
132             }
133             ;
134             return false;
135           }
136           if (!thcycle) {
137             if (!this._organization.equals(temp._organization)) {
138               org.castor.util.CycleBreaker
139                   .releaseCycleHandle(this._organization);
140               org.castor.util.CycleBreaker
141                   .releaseCycleHandle(temp._organization);
142               return false;
143             }
144             org.castor.util.CycleBreaker.releaseCycleHandle(this._organization);
145             org.castor.util.CycleBreaker.releaseCycleHandle(temp._organization);
146           }
147         }
148       } else if (temp._organization != null)
149         return false;
150       return true;
151     }
152     return false;
153   }
154
155   /**
156    * Returns the value of field 'fullname'.
157    * 
158    * @return the value of field 'Fullname'.
159    */
160   public java.lang.String getFullname() {
161     return this._fullname;
162   }
163
164   /**
165    * Returns the value of field 'organization'.
166    * 
167    * @return the value of field 'Organization'.
168    */
169   public java.lang.String getOrganization() {
170     return this._organization;
171   }
172
173   /**
174    * Overrides the java.lang.Object.hashCode method.
175    * <p>
176    * The following steps came from <b>Effective Java Programming Language
177    * Guide</b> by Joshua Bloch, Chapter 3
178    * 
179    * @return a hash code value for the object.
180    */
181   public int hashCode() {
182     int result = super.hashCode();
183
184     long tmp;
185     if (_fullname != null
186         && !org.castor.util.CycleBreaker.startingToCycle(_fullname)) {
187       result = 37 * result + _fullname.hashCode();
188       org.castor.util.CycleBreaker.releaseCycleHandle(_fullname);
189     }
190     if (_organization != null
191         && !org.castor.util.CycleBreaker.startingToCycle(_organization)) {
192       result = 37 * result + _organization.hashCode();
193       org.castor.util.CycleBreaker.releaseCycleHandle(_organization);
194     }
195
196     return result;
197   }
198
199   /**
200    * Method isValid.
201    * 
202    * @return true if this object is valid according to the schema
203    */
204   public boolean isValid() {
205     try {
206       validate();
207     } catch (org.exolab.castor.xml.ValidationException vex) {
208       return false;
209     }
210     return true;
211   }
212
213   /**
214    * 
215    * 
216    * @param out
217    * @throws org.exolab.castor.xml.MarshalException
218    *           if object is null or if any SAXException is thrown during
219    *           marshaling
220    * @throws org.exolab.castor.xml.ValidationException
221    *           if this object is an invalid instance according to the schema
222    */
223   public void marshal(final java.io.Writer out)
224       throws org.exolab.castor.xml.MarshalException,
225       org.exolab.castor.xml.ValidationException {
226     Marshaller.marshal(this, out);
227   }
228
229   /**
230    * 
231    * 
232    * @param handler
233    * @throws java.io.IOException
234    *           if an IOException occurs during marshaling
235    * @throws org.exolab.castor.xml.ValidationException
236    *           if this object is an invalid instance according to the schema
237    * @throws org.exolab.castor.xml.MarshalException
238    *           if object is null or if any SAXException is thrown during
239    *           marshaling
240    */
241   public void marshal(final org.xml.sax.ContentHandler handler)
242       throws java.io.IOException, org.exolab.castor.xml.MarshalException,
243       org.exolab.castor.xml.ValidationException {
244     Marshaller.marshal(this, handler);
245   }
246
247   /**
248    * Sets the value of field 'fullname'.
249    * 
250    * @param fullname
251    *          the value of field 'fullname'.
252    */
253   public void setFullname(final java.lang.String fullname) {
254     this._fullname = fullname;
255   }
256
257   /**
258    * Sets the value of field 'organization'.
259    * 
260    * @param organization
261    *          the value of field 'organization'.
262    */
263   public void setOrganization(final java.lang.String organization) {
264     this._organization = organization;
265   }
266
267   /**
268    * Method unmarshal.
269    * 
270    * @param reader
271    * @throws org.exolab.castor.xml.MarshalException
272    *           if object is null or if any SAXException is thrown during
273    *           marshaling
274    * @throws org.exolab.castor.xml.ValidationException
275    *           if this object is an invalid instance according to the schema
276    * @return the unmarshaled uk.ac.vamsas.objects.core.AppData
277    */
278   public static uk.ac.vamsas.objects.core.AppData unmarshal(
279       final java.io.Reader reader)
280       throws org.exolab.castor.xml.MarshalException,
281       org.exolab.castor.xml.ValidationException {
282     return (uk.ac.vamsas.objects.core.AppData) Unmarshaller.unmarshal(
283         uk.ac.vamsas.objects.core.User.class, reader);
284   }
285
286   /**
287    * 
288    * 
289    * @throws org.exolab.castor.xml.ValidationException
290    *           if this object is an invalid instance according to the schema
291    */
292   public void validate() throws org.exolab.castor.xml.ValidationException {
293     org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
294     validator.validate(this);
295   }
296
297 }