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