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