KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > jtrac > domain > ItemUser


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package info.jtrac.domain;
18
19 import java.io.Serializable JavaDoc;
20
21 /**
22  * Class that exists purely to hold a single user associated with an item
23  * along with a integer "type" indicating the nature of the relationship
24  * between Item --> User (one directional relationship)
25  *
26  * This is used in the following cases
27  * - users "watching" an Item and need to be notified on Status changes
28  *
29  * and can be used for other kinds of relationships in the future
30  */

31 public class ItemUser implements Serializable JavaDoc {
32     
33     private long id;
34     private User user;
35     private int type;
36     
37     public ItemUser() {
38         // zero arg constructor
39
}
40     
41     public ItemUser(User user) {
42         this.user = user;
43     }
44     
45     public ItemUser(User user, int type) {
46         this.user = user;
47         this.type = type;
48     }
49
50     //=================================================
51

52     public long getId() {
53         return id;
54     }
55
56     public void setId(long id) {
57         this.id = id;
58     }
59
60     public User getUser() {
61         return user;
62     }
63
64     public void setUser(User user) {
65         this.user = user;
66     }
67
68     public int getType() {
69         return type;
70     }
71
72     public void setType(int type) {
73         this.type = type;
74     }
75     
76     @Override JavaDoc
77     public String JavaDoc toString() {
78         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
79         sb.append("id [").append(id);
80         sb.append("]; user [").append(user);
81         sb.append("]; type [").append(type);
82         sb.append("]");
83         return sb.toString();
84     }
85     
86     @Override JavaDoc
87     public boolean equals(Object JavaDoc o) {
88         if (this == o) {
89             return true;
90         }
91         if (!(o instanceof ItemUser)) {
92             return false;
93         }
94         final ItemUser iu = (ItemUser) o;
95         return (user.equals(iu.getUser()) && type == iu.getType());
96     }
97     
98     @Override JavaDoc
99     public int hashCode() {
100         int hash = 7;
101         hash = hash * 31 + user.hashCode();
102         hash = hash * 31 + type;
103         return hash;
104     }
105     
106 }
107
Popular Tags