KickJava   Java API By Example, From Geeks To Geeks.

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


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 item related to another item
23  * along with a integer "type" indicating the nature of the relationship
24  * between Item --> Item (one directional relationship)
25  *
26  * This is used in the following cases
27  * - item is a duplicate of another
28  * - item depends on another
29  *
30  * and can be used for other kinds of relationships in the future
31  */

32 public class ItemItem implements Serializable JavaDoc {
33     
34     private long id;
35     private Item item;
36     private Item relatedItem;
37     private int type;
38
39     public static int RELATED = 0;
40     public static int DUPLICATE_OF = 1;
41     public static int DEPENDS_ON = 2;
42     
43     // this returns i18n keys
44
public static String JavaDoc getRelationText(int type) {
45         if (type == RELATED) {
46             return "relatedTo";
47         } else if (type == DUPLICATE_OF) {
48             return "duplicateOf";
49         } else if (type == DEPENDS_ON) {
50             return "dependsOn";
51         } else {
52             throw new RuntimeException JavaDoc("unknown type: " + type);
53         }
54     }
55     
56     public ItemItem() {
57         // zero arg constructor
58
}
59     
60     public ItemItem(Item item, Item relatedItem, int type) {
61         this.item = item;
62         this.relatedItem = relatedItem;
63         this.type = type;
64     }
65     
66     public String JavaDoc getRelationText() {
67         return getRelationText(type);
68     }
69     
70     //=================================================
71

72     public long getId() {
73         return id;
74     }
75
76     public void setId(long id) {
77         this.id = id;
78     }
79
80     public Item getItem() {
81         return item;
82     }
83
84     public void setItem(Item item) {
85         this.item = item;
86     }
87     
88     public Item getRelatedItem() {
89         return relatedItem;
90     }
91
92     public void setRelatedItem(Item relatedItem) {
93         this.relatedItem = relatedItem;
94     }
95
96     public int getType() {
97         return type;
98     }
99
100     public void setType(int type) {
101         this.type = type;
102     }
103     
104     @Override JavaDoc
105     public String JavaDoc toString() {
106         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
107         sb.append("id [").append(id);
108         sb.append("]; item [").append(item);
109         sb.append("]; type [").append(type);
110         sb.append("]");
111         return sb.toString();
112     }
113     
114     @Override JavaDoc
115     public boolean equals(Object JavaDoc o) {
116         if (this == o) {
117             return true;
118         }
119         if (!(o instanceof ItemItem)) {
120             return false;
121         }
122         final ItemItem ii = (ItemItem) o;
123         return (item.equals(ii.getItem()) && type == ii.getType());
124     }
125     
126     @Override JavaDoc
127     public int hashCode() {
128         int hash = 7;
129         hash = hash * 31 + item.hashCode();
130         hash = hash * 31 + type;
131         return hash;
132     }
133     
134 }
135
Popular Tags