1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.service.persistence;
16  
17  import com.liferay.portal.kernel.util.StringBundler;
18  import com.liferay.portal.kernel.util.StringPool;
19  
20  import java.io.Serializable;
21  
22  /**
23   * <a href="UserGroupRolePK.java.html"><b><i>View Source</i></b></a>
24   *
25   * @author Brian Wing Shun Chan
26   */
27  public class UserGroupRolePK implements Comparable<UserGroupRolePK>,
28      Serializable {
29      public long userId;
30      public long groupId;
31      public long roleId;
32  
33      public UserGroupRolePK() {
34      }
35  
36      public UserGroupRolePK(long userId, long groupId, long roleId) {
37          this.userId = userId;
38          this.groupId = groupId;
39          this.roleId = roleId;
40      }
41  
42      public long getUserId() {
43          return userId;
44      }
45  
46      public void setUserId(long userId) {
47          this.userId = userId;
48      }
49  
50      public long getGroupId() {
51          return groupId;
52      }
53  
54      public void setGroupId(long groupId) {
55          this.groupId = groupId;
56      }
57  
58      public long getRoleId() {
59          return roleId;
60      }
61  
62      public void setRoleId(long roleId) {
63          this.roleId = roleId;
64      }
65  
66      public int compareTo(UserGroupRolePK pk) {
67          if (pk == null) {
68              return -1;
69          }
70  
71          int value = 0;
72  
73          if (userId < pk.userId) {
74              value = -1;
75          }
76          else if (userId > pk.userId) {
77              value = 1;
78          }
79          else {
80              value = 0;
81          }
82  
83          if (value != 0) {
84              return value;
85          }
86  
87          if (groupId < pk.groupId) {
88              value = -1;
89          }
90          else if (groupId > pk.groupId) {
91              value = 1;
92          }
93          else {
94              value = 0;
95          }
96  
97          if (value != 0) {
98              return value;
99          }
100 
101         if (roleId < pk.roleId) {
102             value = -1;
103         }
104         else if (roleId > pk.roleId) {
105             value = 1;
106         }
107         else {
108             value = 0;
109         }
110 
111         if (value != 0) {
112             return value;
113         }
114 
115         return 0;
116     }
117 
118     public boolean equals(Object obj) {
119         if (obj == null) {
120             return false;
121         }
122 
123         UserGroupRolePK pk = null;
124 
125         try {
126             pk = (UserGroupRolePK)obj;
127         }
128         catch (ClassCastException cce) {
129             return false;
130         }
131 
132         if ((userId == pk.userId) && (groupId == pk.groupId) &&
133                 (roleId == pk.roleId)) {
134             return true;
135         }
136         else {
137             return false;
138         }
139     }
140 
141     public int hashCode() {
142         return (String.valueOf(userId) + String.valueOf(groupId) +
143         String.valueOf(roleId)).hashCode();
144     }
145 
146     public String toString() {
147         StringBundler sb = new StringBundler(15);
148 
149         sb.append(StringPool.OPEN_CURLY_BRACE);
150 
151         sb.append("userId");
152         sb.append(StringPool.EQUAL);
153         sb.append(userId);
154 
155         sb.append(StringPool.COMMA);
156         sb.append(StringPool.SPACE);
157         sb.append("groupId");
158         sb.append(StringPool.EQUAL);
159         sb.append(groupId);
160 
161         sb.append(StringPool.COMMA);
162         sb.append(StringPool.SPACE);
163         sb.append("roleId");
164         sb.append(StringPool.EQUAL);
165         sb.append(roleId);
166 
167         sb.append(StringPool.CLOSE_CURLY_BRACE);
168 
169         return sb.toString();
170     }
171 }