KickJava   Java API By Example, From Geeks To Geeks.

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


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.ReportUtilities;
24
25 public class ReportModel extends GenericModel implements Comparator JavaDoc {
26     private String JavaDoc name;
27     private String JavaDoc nameKey;
28     private String JavaDoc description;
29     private int dataType;
30     private int reportType;
31     private byte[] fileData;
32     private String JavaDoc className;
33
34     public ReportModel() {
35         name = "";
36         nameKey = null;
37         description = "";
38         dataType = 0;
39         reportType = 0;
40         fileData = new byte[0];
41         className = null;
42     }
43
44     public String JavaDoc getName() {
45         return name;
46     }
47
48     public void setName(String JavaDoc value) {
49         name = value;
50     }
51
52     public String JavaDoc getNameKey() {
53         return nameKey;
54     }
55
56     public void setNameKey(String JavaDoc value) {
57         nameKey = value;
58     }
59
60     public String JavaDoc getDescription() {
61         return description;
62     }
63
64     public void setDescription(String JavaDoc value) {
65         description = value;
66     }
67
68     public int getDataType() {
69         return dataType;
70     }
71
72     public void setDataType(int value) {
73         dataType = value;
74     }
75
76     public int getReportType() {
77         return reportType;
78     }
79
80     public void setReportType(int value) {
81         reportType = value;
82     }
83
84     public byte[] getFileData() {
85         return fileData;
86     }
87
88     public void setFileData(byte[] value) {
89         fileData = (value != null && value.length > 0 ? value : new byte[0]);
90     }
91
92     public String JavaDoc getClassName() {
93         return className;
94     }
95
96     public void setClassName(String JavaDoc value) {
97         className = value;
98     }
99
100     public String JavaDoc toString() {
101         return "Report [" + getId() + "] Name: " + getName() + " Name Key: " + getNameKey() + " Data Type: " + getDataType() +
102                " Report Type: " + getReportType() + " Class: " + getClassName() + " Definition Size: " + getFileData().length;
103     }
104
105     public int compare(Object JavaDoc a, Object JavaDoc b) {
106         return this.new CompareById().compare(a, b);
107     }
108
109     public boolean equals(Object JavaDoc obj) {
110         return this.new CompareById().equals(obj);
111     }
112
113     public int hashCode() {
114         return this.new CompareById().hashCode();
115     }
116
117     public abstract class ReportModelComparator implements Comparator JavaDoc {
118         protected boolean isAscending = true;
119
120         public ReportModelComparator() {
121         }
122
123         public ReportModelComparator(boolean isAscending) {
124             setAscending(isAscending);
125         }
126
127         public void setAscending(boolean value) {
128             this.isAscending = value;
129         }
130
131         public boolean equals(Object JavaDoc obj) {
132             if(! (obj instanceof ReportModel)) {
133                 return false;
134             }
135
136             try {
137                 ReportModel mo = (ReportModel) obj;
138                 if(ReportModel.this.getId() == mo.getId()) {
139                     return true;
140                 }
141             } catch(ClassCastException JavaDoc cce) {
142             }
143
144             return false;
145         }
146
147         public int hashCode() {
148             return (ReportModel.this.getId() == null ? 1 : ReportModel.this.getId().intValue());
149         }
150
151         public final int compare(Object JavaDoc a, Object JavaDoc b) {
152             if(! (a instanceof ReportModel) || ! (b instanceof ReportModel)) {
153                 throw new ClassCastException JavaDoc();
154             }
155
156             ReportModel ma = (ReportModel) a;
157             ReportModel mb = (ReportModel) b;
158
159             int result = doComparison(ma, mb);
160             if(! isAscending) {
161                 result = result * -1;
162             }
163             return result;
164         }
165
166         protected int doComparison(ReportModel ma, ReportModel mb) {
167             if(ma.getId() == null) {
168                 return -1;
169             } else if(mb.getId() == null) {
170                 return 1;
171             }
172
173             return ma.getId().compareTo(mb.getId());
174         }
175     }
176
177     public class CompareById extends ReportModelComparator {
178         public CompareById(){
179           super();
180         }
181
182         public CompareById(boolean isAscending) {
183           super(isAscending);
184         }
185     }
186
187     public class CompareByDefinition extends ReportModelComparator {
188         public CompareByDefinition(){
189           super();
190         }
191
192         public CompareByDefinition(boolean isAscending) {
193           super(isAscending);
194         }
195
196         public boolean equals(Object JavaDoc obj) {
197             if(! (obj instanceof ReportModel)) {
198                 return false;
199             }
200
201             try {
202                 ReportModel mo = (ReportModel) obj;
203                 if(ReportModel.this.getName().equals(mo.getName()) &&
204                    ReportModel.this.getDescription().equals(mo.getDescription()) &&
205                    ReportModel.this.getNameKey().equals(mo.getNameKey())) {
206                     return true;
207                 }
208             } catch(Exception JavaDoc e) {
209             }
210
211             return false;
212         }
213
214         public int hashCode() {
215             return ((ReportModel.this.getName() == null ? 1 : ReportModel.this.getName().hashCode()) ^
216                     (ReportModel.this.getDescription() == null ? 1 : ReportModel.this.getDescription().hashCode()) ^
217                     (ReportModel.this.getNameKey() == null ? 1 : ReportModel.this.getNameKey().hashCode()));
218         }
219     }
220 }
Popular Tags