001: /*
002: * Copyright 2002-2005 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package info.jtrac.domain;
018:
019: import java.io.Serializable;
020:
021: /**
022: * Class that exists purely to hold a single item related to another item
023: * along with a integer "type" indicating the nature of the relationship
024: * between Item --> Item (one directional relationship)
025: *
026: * This is used in the following cases
027: * - item is a duplicate of another
028: * - item depends on another
029: *
030: * and can be used for other kinds of relationships in the future
031: */
032: public class ItemItem implements Serializable {
033:
034: private long id;
035: private Item item;
036: private Item relatedItem;
037: private int type;
038:
039: public static final int RELATED = 0;
040: public static final int DUPLICATE_OF = 1;
041: public static final int DEPENDS_ON = 2;
042:
043: // this returns i18n keys
044: public static String getRelationText(int type) {
045: if (type == RELATED) {
046: return "relatedTo";
047: } else if (type == DUPLICATE_OF) {
048: return "duplicateOf";
049: } else if (type == DEPENDS_ON) {
050: return "dependsOn";
051: } else {
052: throw new RuntimeException("unknown type: " + type);
053: }
054: }
055:
056: public ItemItem() {
057: // zero arg constructor
058: }
059:
060: public ItemItem(Item item, Item relatedItem, int type) {
061: this .item = item;
062: this .relatedItem = relatedItem;
063: this .type = type;
064: }
065:
066: public String getRelationText() {
067: return getRelationText(type);
068: }
069:
070: //=================================================
071:
072: public long getId() {
073: return id;
074: }
075:
076: public void setId(long id) {
077: this .id = id;
078: }
079:
080: public Item getItem() {
081: return item;
082: }
083:
084: public void setItem(Item item) {
085: this .item = item;
086: }
087:
088: public Item getRelatedItem() {
089: return relatedItem;
090: }
091:
092: public void setRelatedItem(Item relatedItem) {
093: this .relatedItem = relatedItem;
094: }
095:
096: public int getType() {
097: return type;
098: }
099:
100: public void setType(int type) {
101: this .type = type;
102: }
103:
104: @Override
105: public String toString() {
106: StringBuffer sb = new StringBuffer();
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
115: public boolean equals(Object 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 (id == ii.getId());
124: }
125:
126: @Override
127: public int hashCode() {
128: return (int) id;
129: }
130:
131: }
|