KickJava   Java API By Example, From Geeks To Geeks.

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


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 PermissionModel extends GenericModel implements Comparator JavaDoc {
24     private int type;
25     private String JavaDoc userLogin;
26     private Integer JavaDoc projectId;
27     private Integer JavaDoc userId;
28
29     public PermissionModel() {
30     }
31
32     public PermissionModel(Integer JavaDoc projectId, int type) {
33         this.projectId = projectId;
34         this.type = type;
35     }
36
37     public PermissionModel(Integer JavaDoc projectId, int type, String JavaDoc userLogin) {
38         this(projectId, type);
39         this.userLogin = userLogin;
40     }
41
42     public PermissionModel(Integer JavaDoc projectId, int type, String JavaDoc userLogin, Integer JavaDoc userId) {
43         this(projectId, type, userLogin);
44         this.userId = userId;
45     }
46
47     public int getPermissionType() {
48         return type;
49     }
50
51     public void setPermissionType(int value) {
52         type = value;
53     }
54
55     public String JavaDoc getUserLogin() {
56         return userLogin;
57     }
58
59     public void setUserLogin(String JavaDoc value) {
60         userLogin = value;
61     }
62
63     public Integer JavaDoc getUserId() {
64         return userId;
65     }
66
67     public void setUserId(Integer JavaDoc value) {
68         userId = value;
69     }
70
71     public Integer JavaDoc getProjectId() {
72         return projectId;
73     }
74
75     public void setProjectId(Integer JavaDoc value) {
76         projectId = value;
77     }
78
79     public String JavaDoc toString() {
80         return "User: " + getUserLogin() + "(" + getUserId() + ") Project: " + getProjectId() + " Permission: " + getPermissionType();
81     }
82
83     public int compare(Object JavaDoc a, Object JavaDoc b) {
84         return this.new CompareByPermission().compare(a, b);
85     }
86
87     public boolean equals(Object JavaDoc obj) {
88         return this.new CompareByPermission().equals(obj);
89     }
90
91     public int hashCode() {
92         return this.new CompareByPermission().hashCode();
93     }
94
95     public class CompareByPermission implements Comparator JavaDoc {
96         public int compare(Object JavaDoc a, Object JavaDoc b) {
97             if(! (a instanceof PermissionModel) || ! (b instanceof PermissionModel)) {
98                 throw new ClassCastException JavaDoc();
99             }
100
101             PermissionModel ma = (PermissionModel) a;
102             PermissionModel mb = (PermissionModel) b;
103
104             if(ma.getPermissionType() == mb.getPermissionType()) {
105                 return 0;
106             } else if(ma.getPermissionType() > mb.getPermissionType()) {
107                 return 1;
108             } else {
109                 return -1;
110             }
111         }
112
113         public boolean equals(Object JavaDoc obj) {
114             if(! (obj instanceof PermissionModel)) {
115                 return false;
116             }
117
118             try {
119                 PermissionModel mo = (PermissionModel) obj;
120                 if(PermissionModel.this.getProjectId() == null || mo.getProjectId() == null) {
121                     return false;
122                 }
123
124                 if(PermissionModel.this.getPermissionType() == mo.getPermissionType() &&
125                    PermissionModel.this.getProjectId().intValue() == mo.getProjectId().intValue()) {
126                     return true;
127                 }
128             } catch(ClassCastException JavaDoc cce) {
129             }
130
131             return false;
132         }
133
134         public int hashCode() {
135             return ((PermissionModel.this.getProjectId() == null ? 1 : PermissionModel.this.getProjectId().hashCode()) ^
136                      PermissionModel.this.getPermissionType());
137         }
138     }
139 }
Popular Tags