KickJava   Java API By Example, From Geeks To Geeks.

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


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 Tag associated with an item
23  * along with a integer "type" indicating the nature of the relationship
24  * between Item --> Tag (one directional relationship)
25  *
26  * This is used for allowing an Item to have many Tags, web 2.0 style
27  */

28 public class ItemTag implements Serializable JavaDoc {
29     
30     private long id;
31     private Tag tag;
32     private int type;
33     
34     public ItemTag() {
35         // zero arg constructor
36
}
37     
38     public ItemTag(Tag tag) {
39         this.tag = tag;
40     }
41     
42     public ItemTag(Tag tag, int type) {
43         this.tag = tag;
44         this.type = type;
45     }
46
47     //=================================================
48

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