001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.service.persistence;
022:
023: import com.liferay.portal.kernel.util.StringMaker;
024: import com.liferay.portal.kernel.util.StringPool;
025:
026: import java.io.Serializable;
027:
028: /**
029: * <a href="UserGroupRolePK.java.html"><b><i>View Source</i></b></a>
030: *
031: * @author Brian Wing Shun Chan
032: *
033: */
034: public class UserGroupRolePK implements Comparable, Serializable {
035: public long userId;
036: public long groupId;
037: public long roleId;
038:
039: public UserGroupRolePK() {
040: }
041:
042: public UserGroupRolePK(long userId, long groupId, long roleId) {
043: this .userId = userId;
044: this .groupId = groupId;
045: this .roleId = roleId;
046: }
047:
048: public long getUserId() {
049: return userId;
050: }
051:
052: public void setUserId(long userId) {
053: this .userId = userId;
054: }
055:
056: public long getGroupId() {
057: return groupId;
058: }
059:
060: public void setGroupId(long groupId) {
061: this .groupId = groupId;
062: }
063:
064: public long getRoleId() {
065: return roleId;
066: }
067:
068: public void setRoleId(long roleId) {
069: this .roleId = roleId;
070: }
071:
072: public int compareTo(Object obj) {
073: if (obj == null) {
074: return -1;
075: }
076:
077: UserGroupRolePK pk = (UserGroupRolePK) obj;
078:
079: int value = 0;
080:
081: if (userId < pk.userId) {
082: value = -1;
083: } else if (userId > pk.userId) {
084: value = 1;
085: } else {
086: value = 0;
087: }
088:
089: if (value != 0) {
090: return value;
091: }
092:
093: if (groupId < pk.groupId) {
094: value = -1;
095: } else if (groupId > pk.groupId) {
096: value = 1;
097: } else {
098: value = 0;
099: }
100:
101: if (value != 0) {
102: return value;
103: }
104:
105: if (roleId < pk.roleId) {
106: value = -1;
107: } else if (roleId > pk.roleId) {
108: value = 1;
109: } else {
110: value = 0;
111: }
112:
113: if (value != 0) {
114: return value;
115: }
116:
117: return 0;
118: }
119:
120: public boolean equals(Object obj) {
121: if (obj == null) {
122: return false;
123: }
124:
125: UserGroupRolePK pk = null;
126:
127: try {
128: pk = (UserGroupRolePK) obj;
129: } catch (ClassCastException cce) {
130: return false;
131: }
132:
133: if ((userId == pk.userId) && (groupId == pk.groupId)
134: && (roleId == pk.roleId)) {
135: return true;
136: } else {
137: return false;
138: }
139: }
140:
141: public int hashCode() {
142: return (String.valueOf(userId) + String.valueOf(groupId) + String
143: .valueOf(roleId)).hashCode();
144: }
145:
146: public String toString() {
147: StringMaker sm = new StringMaker();
148:
149: sm.append(StringPool.OPEN_CURLY_BRACE);
150:
151: sm.append("userId");
152: sm.append(StringPool.EQUAL);
153: sm.append(userId);
154:
155: sm.append(StringPool.COMMA);
156: sm.append(StringPool.SPACE);
157: sm.append("groupId");
158: sm.append(StringPool.EQUAL);
159: sm.append(groupId);
160:
161: sm.append(StringPool.COMMA);
162: sm.append(StringPool.SPACE);
163: sm.append("roleId");
164: sm.append(StringPool.EQUAL);
165: sm.append(roleId);
166:
167: sm.append(StringPool.CLOSE_CURLY_BRACE);
168:
169: return sm.toString();
170: }
171: }
|