KickJava   Java API By Example, From Geeks To Geeks.

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


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 import cowsultants.itracker.ejb.client.util.*;
24
25 public class IssueHistoryModel extends GenericModel implements Comparator JavaDoc {
26     private String JavaDoc description;
27     private int status;
28
29     private Integer JavaDoc issueId;
30     private Integer JavaDoc userId;
31
32     private UserModel user;
33
34     public IssueHistoryModel() {
35         userId = new Integer JavaDoc(-1);
36     }
37
38     public IssueHistoryModel(String JavaDoc description) {
39         this();
40         this.setDescription(description);
41         this.setStatus(IssueUtilities.HISTORY_STATUS_AVAILABLE);
42     }
43
44     public IssueHistoryModel(String JavaDoc description, int status, Integer JavaDoc issueId, Integer JavaDoc userId) {
45         this();
46         this.setDescription(description);
47         this.setIssueId(issueId);
48         this.setUserId(userId);
49         this.setStatus(status);
50     }
51
52     public String JavaDoc getDescription() {
53         return description;
54     }
55
56     public void setDescription(String JavaDoc value) {
57          description = value;
58     }
59
60     public int getStatus() {
61         return status;
62     }
63
64     public void setStatus(int value) {
65          status = value;
66     }
67
68     public UserModel getUser() {
69         return user;
70     }
71
72     public void setUser(UserModel value) {
73         user = value;
74     }
75
76     public Integer JavaDoc getUserId() {
77         return (user == null ? userId : user.getId());
78     }
79
80     public void setUserId(Integer JavaDoc value) {
81          userId = value;
82     }
83
84     public String JavaDoc getUserLogin() {
85         return (user == null ? "" : user.getLogin());
86     }
87
88     public String JavaDoc getUserFirstName() {
89         return (user == null ? "" : user.getFirstName());
90     }
91
92     public String JavaDoc getUserLastName() {
93         return (user == null ? "" : user.getLastName());
94     }
95
96     public String JavaDoc getUserEmail() {
97         return (user == null ? "" : user.getEmail());
98     }
99
100     public Integer JavaDoc getIssueId() {
101         return issueId;
102     }
103
104     public void setIssueId(Integer JavaDoc value) {
105          issueId = value;
106     }
107
108     public int compare(Object JavaDoc a, Object JavaDoc b) {
109         return this.new CompareByDate().compare(a, b);
110     }
111
112     public boolean equals(Object JavaDoc obj) {
113         return this.new CompareByDate().equals(obj);
114     }
115
116     public int hashCode() {
117         return this.new CompareByDate().hashCode();
118     }
119
120     public String JavaDoc toString() {
121         return "IssueHistory [" + this.getId() + "] Issue: " + this.getIssueId() + " Creator: " + this.getUserId() + " Description: " + this.getDescription();
122     }
123
124     public class CompareByDate implements Comparator JavaDoc {
125         protected boolean isAscending = true;
126
127         public CompareByDate() {
128         }
129
130         public CompareByDate(boolean isAscending) {
131             setAscending(isAscending);
132         }
133
134         public void setAscending(boolean value) {
135             this.isAscending = value;
136         }
137
138         public int compare(Object JavaDoc a, Object JavaDoc b) {
139             int result = 0;
140
141             if(! (a instanceof IssueHistoryModel) || ! (b instanceof IssueHistoryModel)) {
142                 throw new ClassCastException JavaDoc();
143             }
144
145             IssueHistoryModel ma = (IssueHistoryModel) a;
146             IssueHistoryModel mb = (IssueHistoryModel) b;
147
148             if(ma.getCreateDate() == null && mb.getCreateDate() == null) {
149                 result = 0;
150             } else if(ma.getCreateDate() == null) {
151                 result = 1;
152             } else if(mb.getCreateDate() == null) {
153                 result = -1;
154             } else {
155                 if(ma.getCreateDate().equals(mb.getCreateDate())) {
156                     result = 0;
157                 } else if(ma.getCreateDate().before(mb.getCreateDate())) {
158                     result = -1;
159                 } else {
160                     result = 1;
161                 }
162             }
163
164             return (isAscending ? result : result * -1);
165         }
166
167         public boolean equals(Object JavaDoc obj) {
168             if(! (obj instanceof IssueHistoryModel)) {
169                 return false;
170             }
171
172             try {
173                 IssueHistoryModel mo = (IssueHistoryModel) obj;
174                 if(IssueHistoryModel.this.getCreateDate().equals(mo.getCreateDate()) &&
175                    IssueHistoryModel.this.getUserLogin().equals(mo.getUserLogin()) &&
176                    IssueHistoryModel.this.getDescription().equals(mo.getDescription())) {
177                     return true;
178                 }
179             } catch(ClassCastException JavaDoc cce) {
180             }
181
182             return false;
183         }
184
185         public int hashCode() {
186             return ((IssueHistoryModel.this.getCreateDate() == null ? 1 : IssueHistoryModel.this.getCreateDate().hashCode()) ^
187                     IssueHistoryModel.this.getUserLogin().hashCode() ^
188                     (IssueHistoryModel.this.getDescription() == null ? 1 : IssueHistoryModel.this.getDescription().hashCode()));
189         }
190     }
191 }
Popular Tags