View Javadoc

1   package org.sourceforge.vlibrary.user.domain;
2   
3   import org.apache.commons.lang.StringUtils;
4   
5   
6   /**
7    * registered reader<br>
8    *
9    * @version $Revision$ $Date$
10   */
11  
12  public class Reader {
13      private long id = 0;
14      private String lastName = null;
15      private String firstName = null;
16      private String email=null;
17      private String deskPhone=null;
18      private String mobilePhone=null;
19      private String pager="";
20      private String screenName="";
21      private String imService="";
22      private String uid="";
23      private String pwd="";
24      private boolean administrator=false;
25  
26      public Reader() {
27      }
28  
29      public Reader(
30       String lastName,
31       String firstName,
32       String email,
33       String deskPhone,
34       String mobilePhone,
35       String pager,
36       String screenName,
37       String imService,
38       String uid,
39       String pwd,
40       boolean administrator ) {
41          this.lastName = lastName;
42          this.firstName = firstName;
43          this.email = email;
44          this.deskPhone = deskPhone;
45          this.mobilePhone = mobilePhone;
46          this.pager = pager;
47          this.screenName = screenName;
48          this.imService = imService;
49          this.uid = uid;
50          this.pwd = pwd;
51          this.administrator = administrator;
52      }
53  
54      public String toString() {
55          return  "<Reader "              +
56           "id=\""                 + id +
57           "\" lastName=\""        + lastName +
58           "\" firstName=\""       + firstName +
59           "\" email=\""           + email +
60           "\" deskPhone=\""       + deskPhone +
61           "\" mobilePhone=\""     + mobilePhone +
62           "\" pager=\""           + pager +
63           "\" screenName=\""      + screenName +
64           "\" imService=\""       + imService +
65           "\" uid=\""             + uid +
66           "\" administrator=\""   + administrator +
67           "\" />";
68      }
69  
70      public Reader(String email) {
71          this.email=email;
72      }
73  
74      public String getFirstName() {
75          return firstName;
76      }
77  
78      public long getId() {
79          return id;
80      }
81  
82      public String getLastName() {
83          return lastName;
84      }
85  
86      public void setFirstName(String firstName) {
87          this.firstName = firstName;
88      }
89  
90      public void setId(long id) {
91          this.id = id;
92      }
93  
94      public void setId(Long id) {
95          this.id = id.longValue();
96      }
97  
98      public void setId(Integer id) {
99          this.id = id.longValue();
100     }
101 
102     public void setLastName(String lastName) {
103         this.lastName = lastName;
104     }
105 
106     public String getDeskPhone() {
107         return deskPhone;
108     }
109 
110     public void setDeskPhone(String deskPhone) {
111         this.deskPhone = deskPhone;
112     }
113 
114     public String getEmail() {
115         return email;
116     }
117 
118     public void setEmail(String email) {
119         this.email = email;
120     }
121 
122     public String getImService() {
123         return imService;
124     }
125 
126     public void setImService(String imService) {
127         this.imService = imService;
128     }
129 
130     public String getMobilePhone() {
131         return mobilePhone;
132     }
133 
134     public void setMobilePhone(String mobilePhone) {
135         this.mobilePhone = mobilePhone;
136     }
137 
138     public String getPager() {
139         return pager;
140     }
141 
142     public void setPager(String pager) {
143         this.pager = pager;
144     }
145 
146     public String getPwd() {
147         return pwd;
148     }
149 
150     public void setPwd(String pwd) {
151         this.pwd = pwd;
152     }
153 
154     public String getScreenName() {
155         return screenName;
156     }
157 
158     public void setScreenName(String screenName) {
159         this.screenName = screenName;
160     }
161 
162     public String getUid() {
163         return uid;
164     }
165 
166     public void setUid(String uid) {
167         this.uid = uid;
168     }
169 
170     public boolean isAdministrator() {
171         return administrator;
172     }
173 
174     public void setAdministrator(boolean administrator) {
175         this.administrator = administrator;
176     }
177 
178     /**
179      * Normalizes phone numbers to nnn-nnn-nnnn format by stripping
180      * all non-numeric chars and replacing with "-", other than initial
181      * chars and sequences of more than one non-numeric char (skipped)
182      *
183      * @param phoneString - the input phone number string
184      */
185     public String normalizePhone(String phoneString) {
186         if ((phoneString == null) || (phoneString.length() == 0)) {
187             return "";
188         }
189 
190         StringBuffer out = new StringBuffer();
191         String thisChar = "";
192         String lagChar="x";
193         String inString = phoneString.trim();
194 
195         for (int i = 0; i<inString.length(); i++) {
196             thisChar = inString.substring(i,i+1);
197 
198             if (StringUtils.isNumeric(thisChar)) {
199                 out.append(thisChar);
200             } else {
201                 if (StringUtils.isNumeric(lagChar))
202                     out.append("-");
203             }
204             lagChar = thisChar;
205         }
206         return out.toString();
207     }
208 
209     /**
210      * Returns true iff obj is a reader and admin status, id, deskPhone, mobilePhone,
211      * email, firstName, lastName, imService, pager, screenName and uid fields match
212      * the values of this exactly. Allows null field values in comparisons.
213      *
214      * @param obj the object to test
215      * @return true if obj equals this
216      */
217     public boolean equals(Object obj) {
218         if (this == obj) {
219             return true;
220         }
221 
222         if((obj == null) || !(obj instanceof Reader)) {
223             return false;
224         }
225 
226         Reader reader = (Reader) obj;
227 
228         if (this.deskPhone == null && reader.getDeskPhone() != null) {
229             return false;
230         }
231         if (this.email == null && reader.getEmail() != null) {
232             return false;
233         }
234         if (this.firstName == null && reader.getFirstName() != null) {
235             return false;
236         }
237         if (this.lastName == null && reader.getLastName() != null) {
238             return false;
239         }
240         if (this.mobilePhone == null && reader.getMobilePhone() != null) {
241             return false;
242         }
243         if ((this.pager != null && this.pager.equals("")) &&
244          (reader.getPager()!= null &&!reader.getPager().equals(""))) {
245             return false;
246         }
247         if ((this.screenName!= null && this.screenName.equals("")) &&
248          (reader.getScreenName()!= null && !reader.getScreenName().equals(""))) {
249             return false;
250         }
251         if ((this.uid!= null && this.uid.equals("")) &&
252          (reader.getUid() != null && !reader.getUid().equals(""))) {
253             return false;
254         }
255         if ((this.imService != null && this.imService.equals("")) &&
256          (reader.getImService() != null && !reader.getImService().equals(""))) {
257             return false;
258         }
259 
260         return
261          (this.id == reader.getId()) &&
262          (this.deskPhone == null ||
263          this.deskPhone.equals(reader.getDeskPhone())) &&
264          (this.email == null ||
265          this.email.equals(reader.getEmail())) &&
266          (this.firstName == null ||
267          this.firstName.equals(reader.getFirstName())) &&
268          (this.lastName == null ||
269          this.lastName.equals(reader.getLastName())) &&
270          (this.imService == null ||
271          this.imService.equals(reader.getImService())) &&
272          (this.mobilePhone == null ||
273          this.mobilePhone.equals(reader.getMobilePhone())) &&
274          (this.pager == null ||
275          this.pager.equals(reader.getPager())) &&
276          (this.uid == null ||
277          this.uid.equals(reader.getUid())) &&
278          (this.screenName == null ||
279          this.screenName.equals(reader.getScreenName())) &&
280          (this.administrator == reader.isAdministrator());
281     }
282 
283     public int hashCode() {
284         int hash = (int) this.id * 7;
285         String cat = this.deskPhone + "|" + this.email +
286          "|" + this.firstName + "|" + this.lastName + "|" + this.imService +
287          "|" + this.mobilePhone + "|" + this.pager + "|" + this.uid + "|" +
288          this.screenName + "|" + this.administrator;
289         return 31 * hash + cat.hashCode();
290     }
291 
292 
293 }