KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cowsultants > itracker > ejb > client > models > NotificationModel


1 /*
2  * This software was designed and created by Jason Carroll.
3  * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4  * The author can be reached at jcarroll@cowsultants.com
5  * ITracker website: http://www.cowsultants.com
6  * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it only under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  */

18
19 package cowsultants.itracker.ejb.client.models;
20
21 import java.util.Comparator JavaDoc;
22
23 public class NotificationModel extends GenericModel implements Comparator JavaDoc {
24     private int type;
25     private String JavaDoc login;
26     private String JavaDoc firstName;
27     private String JavaDoc lastName;
28     private String JavaDoc email;
29     private Integer JavaDoc userId;
30     private Integer JavaDoc issueId;
31
32     public NotificationModel() {
33         login = "";
34         firstName = "";
35         lastName = "";
36         email = "";
37         userId = new Integer JavaDoc(-1);
38         issueId = new Integer JavaDoc(-1);
39     }
40
41     public NotificationModel(int type) {
42         this.setNotificationRole(type);
43     }
44
45     public NotificationModel(UserModel user, Integer JavaDoc issueId, int type) {
46         this.setUserLogin(user.getLogin());
47         this.setUserFirstName(user.getFirstName());
48         this.setUserLastName(user.getLastName());
49         this.setUserEmail(user.getEmail());
50         this.setUserId(user.getId());
51         this.setIssueId(issueId);
52         this.setNotificationRole(type);
53     }
54
55     public int getNotificationRole() {
56         return type;
57     }
58
59     public void setNotificationRole(int value) {
60         type = value;
61     }
62
63     public String JavaDoc getUserLogin() {
64         return login;
65     }
66
67     public void setUserLogin(String JavaDoc value) {
68          login = value;
69     }
70
71     public String JavaDoc getUserFirstName() {
72         return firstName;
73     }
74
75     public void setUserFirstName(String JavaDoc value) {
76          firstName = value;
77     }
78
79     public String JavaDoc getUserLastName() {
80         return lastName;
81     }
82
83     public void setUserLastName(String JavaDoc value) {
84          lastName = value;
85     }
86
87     public String JavaDoc getUserEmail() {
88         return email;
89     }
90
91     public void setUserEmail(String JavaDoc value) {
92          email = value;
93     }
94
95     public Integer JavaDoc getIssueId() {
96         return issueId;
97     }
98
99     public void setIssueId(Integer JavaDoc value) {
100          issueId = value;
101     }
102
103     public Integer JavaDoc getUserId() {
104         return userId;
105     }
106
107     public void setUserId(Integer JavaDoc value) {
108          userId = value;
109     }
110
111     public int compare(Object JavaDoc a, Object JavaDoc b) {
112         return this.new CompareByName().compare(a, b);
113     }
114
115     public boolean equals(Object JavaDoc obj) {
116         return this.new CompareByName().equals(obj);
117     }
118
119     public int hashCode() {
120         return this.new CompareByName().hashCode();
121     }
122
123     public abstract class NotificationModelComparator implements Comparator JavaDoc {
124         protected boolean isAscending = true;
125
126         public NotificationModelComparator() {
127         }
128
129         public NotificationModelComparator(boolean isAscending) {
130             setAscending(isAscending);
131         }
132
133         public void setAscending(boolean value) {
134             this.isAscending = value;
135         }
136
137         protected abstract int doComparison(NotificationModel ma, NotificationModel mb);
138
139         public final boolean equals(Object JavaDoc obj) {
140             if(! (obj instanceof NotificationModel)) {
141                 return false;
142             }
143
144             try {
145                 NotificationModel mo = (NotificationModel) obj;
146                 if(NotificationModel.this.getUserLogin().equals(mo.getUserLogin())) {
147                     return true;
148                 }
149             } catch(ClassCastException JavaDoc cce) {
150             }
151
152             return false;
153         }
154
155         public int hashCode() {
156             return ((NotificationModel.this.getUserLogin() == null ? 1 : NotificationModel.this.getUserLogin().hashCode()));
157         }
158
159         public final int compare(Object JavaDoc a, Object JavaDoc b) {
160             if(! (a instanceof NotificationModel) || ! (b instanceof NotificationModel)) {
161                 throw new ClassCastException JavaDoc();
162             }
163
164             NotificationModel ma = (NotificationModel) a;
165             NotificationModel mb = (NotificationModel) b;
166
167             int result = doComparison(ma, mb);
168             if(! isAscending) {
169                 result = result * -1;
170             }
171             return result;
172         }
173     }
174
175
176     public class CompareByName extends NotificationModelComparator {
177         public CompareByName(){
178           super();
179         }
180
181         public CompareByName(boolean isAscending) {
182           super(isAscending);
183         }
184
185         protected int doComparison(NotificationModel ma, NotificationModel mb) {
186             if(ma.getUserLastName() == null && mb.getUserLastName() == null) {
187                 return 0;
188             } else if(ma.getUserLastName() == null) {
189                 return 1;
190             } else if(mb.getUserLastName() == null) {
191                 return -1;
192             }
193
194             return (ma.getUserLastName().compareTo(mb.getUserLastName()) == 0 ?
195                     ma.getUserFirstName().compareTo(mb.getUserFirstName()) :
196                     ma.getUserLastName().compareTo(mb.getUserLastName()));
197         }
198     }
199
200     public class CompareByType extends NotificationModelComparator {
201         public CompareByType(){
202           super();
203         }
204
205         public CompareByType(boolean isAscending) {
206           super(isAscending);
207         }
208
209         protected int doComparison(NotificationModel ma, NotificationModel mb) {
210             if(ma.getNotificationRole() == mb.getNotificationRole()) {
211                 return 0;
212             } else if(ma.getNotificationRole() < mb.getNotificationRole()) {
213                 return -1;
214             } else {
215                 return 1;
216             }
217         }
218     }
219
220 }
Popular Tags