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 Tag associated with an item
023: * along with a integer "type" indicating the nature of the relationship
024: * between Item --> Tag (one directional relationship)
025: *
026: * This is used for allowing an Item to have many Tags, web 2.0 style
027: */
028: public class ItemTag implements Serializable {
029:
030: private long id;
031: private Tag tag;
032: private int type;
033:
034: public ItemTag() {
035: // zero arg constructor
036: }
037:
038: public ItemTag(Tag tag) {
039: this .tag = tag;
040: }
041:
042: public ItemTag(Tag tag, int type) {
043: this .tag = tag;
044: this .type = type;
045: }
046:
047: //=================================================
048:
049: public long getId() {
050: return id;
051: }
052:
053: public void setId(long id) {
054: this .id = id;
055: }
056:
057: public Tag getTag() {
058: return tag;
059: }
060:
061: public void setTag(Tag tag) {
062: this .tag = tag;
063: }
064:
065: public int getType() {
066: return type;
067: }
068:
069: public void setType(int type) {
070: this .type = type;
071: }
072:
073: @Override
074: public String toString() {
075: StringBuffer sb = new StringBuffer();
076: sb.append("id [").append(id);
077: sb.append("]; tag [").append(tag);
078: sb.append("]; type [").append(type);
079: sb.append("]");
080: return sb.toString();
081: }
082:
083: @Override
084: public boolean equals(Object o) {
085: if (this == o) {
086: return true;
087: }
088: if (!(o instanceof ItemTag)) {
089: return false;
090: }
091: final ItemTag it = (ItemTag) o;
092: return (tag.equals(it.getTag()) && type == it.getType());
093: }
094:
095: @Override
096: public int hashCode() {
097: int hash = 7;
098: hash = hash * 31 + tag.hashCode();
099: hash = hash * 31 + type;
100: return hash;
101: }
102:
103: }
|