1   /**
2    * Copyright (c) 2000-2007 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.StringMaker;
26  import com.liferay.portal.kernel.util.StringPool;
27  
28  import java.io.Serializable;
29  
30  /**
31   * <a href="OrgGroupRolePK.java.html"><b><i>View Source</i></b></a>
32   *
33   * @author Brian Wing Shun Chan
34   *
35   */
36  public class OrgGroupRolePK implements Comparable, Serializable {
37      public long organizationId;
38      public long groupId;
39      public long roleId;
40  
41      public OrgGroupRolePK() {
42      }
43  
44      public OrgGroupRolePK(long organizationId, long groupId, long roleId) {
45          this.organizationId = organizationId;
46          this.groupId = groupId;
47          this.roleId = roleId;
48      }
49  
50      public long getOrganizationId() {
51          return organizationId;
52      }
53  
54      public void setOrganizationId(long organizationId) {
55          this.organizationId = organizationId;
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(Object obj) {
75          if (obj == null) {
76              return -1;
77          }
78  
79          OrgGroupRolePK pk = (OrgGroupRolePK)obj;
80          int value = 0;
81  
82          if (organizationId < pk.organizationId) {
83              value = -1;
84          }
85          else if (organizationId > pk.organizationId) {
86              value = 1;
87          }
88          else {
89              value = 0;
90          }
91  
92          if (value != 0) {
93              return value;
94          }
95  
96          if (groupId < pk.groupId) {
97              value = -1;
98          }
99          else if (groupId > pk.groupId) {
100             value = 1;
101         }
102         else {
103             value = 0;
104         }
105 
106         if (value != 0) {
107             return value;
108         }
109 
110         if (roleId < pk.roleId) {
111             value = -1;
112         }
113         else if (roleId > pk.roleId) {
114             value = 1;
115         }
116         else {
117             value = 0;
118         }
119 
120         if (value != 0) {
121             return value;
122         }
123 
124         return 0;
125     }
126 
127     public boolean equals(Object obj) {
128         if (obj == null) {
129             return false;
130         }
131 
132         OrgGroupRolePK pk = null;
133 
134         try {
135             pk = (OrgGroupRolePK)obj;
136         }
137         catch (ClassCastException cce) {
138             return false;
139         }
140 
141         if ((organizationId == pk.organizationId) && (groupId == pk.groupId) &&
142                 (roleId == pk.roleId)) {
143             return true;
144         }
145         else {
146             return false;
147         }
148     }
149 
150     public int hashCode() {
151         return (String.valueOf(organizationId) + String.valueOf(groupId) +
152         String.valueOf(roleId)).hashCode();
153     }
154 
155     public String toString() {
156         StringMaker sm = new StringMaker();
157         sm.append(StringPool.OPEN_CURLY_BRACE);
158         sm.append("organizationId");
159         sm.append(StringPool.EQUAL);
160         sm.append(organizationId);
161         sm.append(StringPool.COMMA);
162         sm.append(StringPool.SPACE);
163         sm.append("groupId");
164         sm.append(StringPool.EQUAL);
165         sm.append(groupId);
166         sm.append(StringPool.COMMA);
167         sm.append(StringPool.SPACE);
168         sm.append("roleId");
169         sm.append(StringPool.EQUAL);
170         sm.append(roleId);
171         sm.append(StringPool.CLOSE_CURLY_BRACE);
172 
173         return sm.toString();
174     }
175 }