1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.service.persistence;
24  
25  import com.liferay.portal.kernel.util.StringPool;
26  
27  import java.io.Serializable;
28  
29  /**
30   * <a href="UserGroupRolePK.java.html"><b><i>View Source</i></b></a>
31   *
32   * @author Brian Wing Shun Chan
33   *
34   */
35  public class UserGroupRolePK implements Comparable<UserGroupRolePK>,
36      Serializable {
37      public long userId;
38      public long groupId;
39      public long roleId;
40  
41      public UserGroupRolePK() {
42      }
43  
44      public UserGroupRolePK(long userId, long groupId, long roleId) {
45          this.userId = userId;
46          this.groupId = groupId;
47          this.roleId = roleId;
48      }
49  
50      public long getUserId() {
51          return userId;
52      }
53  
54      public void setUserId(long userId) {
55          this.userId = userId;
56      }
57  
58      public long getGroupId() {
59          return groupId;
60      }
61  
62      public void setGroupId(long groupId) {
63          this.groupId = groupId;
64      }
65  
66      public long getRoleId() {
67          return roleId;
68      }
69  
70      public void setRoleId(long roleId) {
71          this.roleId = roleId;
72      }
73  
74      public int compareTo(UserGroupRolePK pk) {
75          if (pk == null) {
76              return -1;
77          }
78  
79          int value = 0;
80  
81          if (userId < pk.userId) {
82              value = -1;
83          }
84          else if (userId > pk.userId) {
85              value = 1;
86          }
87          else {
88              value = 0;
89          }
90  
91          if (value != 0) {
92              return value;
93          }
94  
95          if (groupId < pk.groupId) {
96              value = -1;
97          }
98          else if (groupId > pk.groupId) {
99              value = 1;
100         }
101         else {
102             value = 0;
103         }
104 
105         if (value != 0) {
106             return value;
107         }
108 
109         if (roleId < pk.roleId) {
110             value = -1;
111         }
112         else if (roleId > pk.roleId) {
113             value = 1;
114         }
115         else {
116             value = 0;
117         }
118 
119         if (value != 0) {
120             return value;
121         }
122 
123         return 0;
124     }
125 
126     public boolean equals(Object obj) {
127         if (obj == null) {
128             return false;
129         }
130 
131         UserGroupRolePK pk = null;
132 
133         try {
134             pk = (UserGroupRolePK)obj;
135         }
136         catch (ClassCastException cce) {
137             return false;
138         }
139 
140         if ((userId == pk.userId) && (groupId == pk.groupId) &&
141                 (roleId == pk.roleId)) {
142             return true;
143         }
144         else {
145             return false;
146         }
147     }
148 
149     public int hashCode() {
150         return (String.valueOf(userId) + String.valueOf(groupId) +
151         String.valueOf(roleId)).hashCode();
152     }
153 
154     public String toString() {
155         StringBuilder sb = new StringBuilder();
156 
157         sb.append(StringPool.OPEN_CURLY_BRACE);
158 
159         sb.append("userId");
160         sb.append(StringPool.EQUAL);
161         sb.append(userId);
162 
163         sb.append(StringPool.COMMA);
164         sb.append(StringPool.SPACE);
165         sb.append("groupId");
166         sb.append(StringPool.EQUAL);
167         sb.append(groupId);
168 
169         sb.append(StringPool.COMMA);
170         sb.append(StringPool.SPACE);
171         sb.append("roleId");
172         sb.append(StringPool.EQUAL);
173         sb.append(roleId);
174 
175         sb.append(StringPool.CLOSE_CURLY_BRACE);
176 
177         return sb.toString();
178     }
179 }