KickJava   Java API By Example, From Geeks To Geeks.

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


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 ComponentModel extends GenericModel implements Comparator JavaDoc {
24     private String JavaDoc name;
25     private String JavaDoc description;
26     private Integer JavaDoc projectId;
27
28     public ComponentModel() {
29         name = "";
30         description = "";
31         projectId = new Integer JavaDoc(-1);
32     }
33
34     public String JavaDoc getName() {
35         return name;
36     }
37
38     public void setName(String JavaDoc value) {
39          name = value;
40     }
41
42     public String JavaDoc getDescription() {
43         return (description == null ? "" : description);
44     }
45
46     public void setDescription(String JavaDoc value) {
47          description = value;
48     }
49
50     public Integer JavaDoc getProjectId() {
51         return projectId;
52     }
53
54     public void setProjectId(Integer JavaDoc value) {
55         projectId = value;
56     }
57
58     public int compare(Object JavaDoc a, Object JavaDoc b) {
59         return this.new CompareByName().compare(a, b);
60     }
61
62     public boolean equals(Object JavaDoc obj) {
63         return this.new CompareByName().equals(obj);
64     }
65
66     public int hashCode() {
67         return this.new CompareByName().hashCode();
68     }
69
70     public String JavaDoc toString() {
71         return "Component [" + this.getId() + "] Project: " + this.getProjectId() + " Name: " + this.getName();
72     }
73
74     public class CompareByName implements Comparator JavaDoc {
75         public int compare(Object JavaDoc a, Object JavaDoc b) {
76             if(! (a instanceof ComponentModel) || ! (b instanceof ComponentModel)) {
77                 throw new ClassCastException JavaDoc();
78             }
79
80             ComponentModel ma = (ComponentModel) a;
81             ComponentModel mb = (ComponentModel) b;
82
83             if(ma.getName() == null && mb.getName() == null) {
84                 return 0;
85             } else if(ma.getName() == null) {
86                 return 1;
87             } else if(mb.getName() == null) {
88                 return -1;
89             }
90
91             return ma.getName().compareTo(mb.getName());
92         }
93
94         public boolean equals(Object JavaDoc obj) {
95             if(! (obj instanceof ComponentModel)) {
96                 return false;
97             }
98
99             try {
100                 ComponentModel mo = (ComponentModel) obj;
101                 if(ComponentModel.this.getName() == mo.getName()) {
102                     return true;
103                 }
104             } catch(ClassCastException JavaDoc cce) {
105             }
106
107             return false;
108         }
109
110         public int hashCode() {
111             return (ComponentModel.this.getName() == null ? 1 : ComponentModel.this.getName().hashCode());
112         }
113     }
114
115 }
Popular Tags