KickJava   Java API By Example, From Geeks To Geeks.

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


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 ProjectModel extends GenericModel implements Comparator JavaDoc {
24     private String JavaDoc name;
25     private String JavaDoc description;
26     private int status;
27     private int options;
28     private CustomFieldModel[] fields;
29     private ComponentModel[] components = null;
30     private VersionModel[] versions = null;
31     private UserModel[] owners = null;
32
33     public ProjectModel() {
34         name = "";
35         description = "";
36     }
37
38     public String JavaDoc getName() {
39         return name;
40     }
41
42     public void setName(String JavaDoc value) {
43          name = value;
44     }
45
46     public String JavaDoc getDescription() {
47         return (description == null ? "" : description);
48     }
49
50     public void setDescription(String JavaDoc value) {
51          description = value;
52     }
53
54     public int getStatus() {
55          return status;
56     }
57
58     public void setStatus(int value) {
59          status = value;
60     }
61
62     public int getOptions() {
63          return (options < 0 ? 0 : options);
64     }
65
66     public void setOptions(int value) {
67          options = (value < 0 ? 0 : value);
68     }
69
70     public CustomFieldModel[] getCustomFields() {
71          return (fields == null ? new CustomFieldModel[0] : fields);
72     }
73
74     public void setCustomFields(CustomFieldModel[] value) {
75          fields = (value == null ? new CustomFieldModel[0] : value);
76     }
77
78     public ComponentModel[] getComponents() {
79         return (components == null ? new ComponentModel[0] : components);
80     }
81
82     public void setComponents(ComponentModel[] value) {
83         if(value != null ) {
84             components = new ComponentModel[value.length];
85             System.arraycopy((Object JavaDoc) value, 0, (Object JavaDoc) components, 0, components.length);
86         }
87     }
88
89     public VersionModel[] getVersions() {
90         return (versions == null ? new VersionModel[0] : versions);
91     }
92
93     public void setVersions(VersionModel[] value) {
94         if(value != null ) {
95             versions = new VersionModel[value.length];
96             System.arraycopy((Object JavaDoc) value, 0, (Object JavaDoc) versions, 0, versions.length);
97         }
98     }
99
100     public UserModel[] getOwners() {
101         return (owners == null ? new UserModel[0] : owners);
102     }
103
104     public void setOwners(UserModel[] value) {
105         if(value != null) {
106             owners = new UserModel[value.length];
107             System.arraycopy((Object JavaDoc) value, 0, (Object JavaDoc) owners, 0, owners.length);
108         }
109     }
110
111     public String JavaDoc toString() {
112         return "Project [" + getId() + "] Name: " + getName() + " Description: " + getDescription() +
113                " Num Components: " + getComponents().length + " Num Versions: " + getVersions().length +
114                " Num Custom Fields: " + getCustomFields().length + " Num Owners: " + getOwners().length;
115     }
116
117     public int compare(Object JavaDoc a, Object JavaDoc b) {
118         return this.new CompareByName().compare(a, b);
119     }
120
121     public boolean equals(Object JavaDoc obj) {
122         return this.new CompareByName().equals(obj);
123     }
124
125     public int hashCode() {
126         return this.new CompareByName().hashCode();
127     }
128
129     public class CompareByName implements Comparator JavaDoc {
130         protected boolean isAscending = true;
131
132         public CompareByName() {
133         }
134
135         public CompareByName(boolean isAscending) {
136             setAscending(isAscending);
137         }
138
139         public void setAscending(boolean value) {
140             this.isAscending = value;
141         }
142
143         public int compare(Object JavaDoc a, Object JavaDoc b) {
144             int result = 0;
145             if(! (a instanceof ProjectModel) || ! (b instanceof ProjectModel)) {
146                 throw new ClassCastException JavaDoc();
147             }
148
149             ProjectModel ma = (ProjectModel) a;
150             ProjectModel mb = (ProjectModel) b;
151
152             if(ma.getName() == null && mb.getName() == null) {
153                 result = 0;
154             } else if(ma.getName() == null) {
155                 result = 1;
156             } else if(mb.getName() == null) {
157                 result = -1;
158             } else {
159                 result = ma.getName().compareTo(mb.getName());
160             }
161
162             return (isAscending ? result : result * -1);
163         }
164
165         public boolean equals(Object JavaDoc obj) {
166             if(! (obj instanceof ProjectModel)) {
167                 return false;
168             }
169
170             try {
171                 ProjectModel mo = (ProjectModel) obj;
172                 if(ProjectModel.this.getId().equals(mo.getId())) {
173                     return true;
174                 }
175             } catch(ClassCastException JavaDoc cce) {
176             }
177
178             return false;
179         }
180
181         public int hashCode() {
182             return (ProjectModel.this.getId() == null ? 1 : ProjectModel.this.getId().intValue());
183         }
184     }
185
186 }
Popular Tags