001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence;
016    
017    import com.liferay.portal.kernel.util.StringBundler;
018    import com.liferay.portal.kernel.util.StringPool;
019    
020    import java.io.Serializable;
021    
022    /**
023     * @author Brian Wing Shun Chan
024     */
025    public class UserGroupRolePK implements Comparable<UserGroupRolePK>,
026            Serializable {
027            public long userId;
028            public long groupId;
029            public long roleId;
030    
031            public UserGroupRolePK() {
032            }
033    
034            public UserGroupRolePK(long userId, long groupId, long roleId) {
035                    this.userId = userId;
036                    this.groupId = groupId;
037                    this.roleId = roleId;
038            }
039    
040            public long getUserId() {
041                    return userId;
042            }
043    
044            public void setUserId(long userId) {
045                    this.userId = userId;
046            }
047    
048            public long getGroupId() {
049                    return groupId;
050            }
051    
052            public void setGroupId(long groupId) {
053                    this.groupId = groupId;
054            }
055    
056            public long getRoleId() {
057                    return roleId;
058            }
059    
060            public void setRoleId(long roleId) {
061                    this.roleId = roleId;
062            }
063    
064            public int compareTo(UserGroupRolePK pk) {
065                    if (pk == null) {
066                            return -1;
067                    }
068    
069                    int value = 0;
070    
071                    if (userId < pk.userId) {
072                            value = -1;
073                    }
074                    else if (userId > pk.userId) {
075                            value = 1;
076                    }
077                    else {
078                            value = 0;
079                    }
080    
081                    if (value != 0) {
082                            return value;
083                    }
084    
085                    if (groupId < pk.groupId) {
086                            value = -1;
087                    }
088                    else if (groupId > pk.groupId) {
089                            value = 1;
090                    }
091                    else {
092                            value = 0;
093                    }
094    
095                    if (value != 0) {
096                            return value;
097                    }
098    
099                    if (roleId < pk.roleId) {
100                            value = -1;
101                    }
102                    else if (roleId > pk.roleId) {
103                            value = 1;
104                    }
105                    else {
106                            value = 0;
107                    }
108    
109                    if (value != 0) {
110                            return value;
111                    }
112    
113                    return 0;
114            }
115    
116            public boolean equals(Object obj) {
117                    if (obj == null) {
118                            return false;
119                    }
120    
121                    UserGroupRolePK pk = null;
122    
123                    try {
124                            pk = (UserGroupRolePK)obj;
125                    }
126                    catch (ClassCastException cce) {
127                            return false;
128                    }
129    
130                    if ((userId == pk.userId) && (groupId == pk.groupId) &&
131                                    (roleId == pk.roleId)) {
132                            return true;
133                    }
134                    else {
135                            return false;
136                    }
137            }
138    
139            public int hashCode() {
140                    return (String.valueOf(userId) + String.valueOf(groupId) +
141                    String.valueOf(roleId)).hashCode();
142            }
143    
144            public String toString() {
145                    StringBundler sb = new StringBundler(15);
146    
147                    sb.append(StringPool.OPEN_CURLY_BRACE);
148    
149                    sb.append("userId");
150                    sb.append(StringPool.EQUAL);
151                    sb.append(userId);
152    
153                    sb.append(StringPool.COMMA);
154                    sb.append(StringPool.SPACE);
155                    sb.append("groupId");
156                    sb.append(StringPool.EQUAL);
157                    sb.append(groupId);
158    
159                    sb.append(StringPool.COMMA);
160                    sb.append(StringPool.SPACE);
161                    sb.append("roleId");
162                    sb.append(StringPool.EQUAL);
163                    sb.append(roleId);
164    
165                    sb.append(StringPool.CLOSE_CURLY_BRACE);
166    
167                    return sb.toString();
168            }
169    }