001    /**
002     * Copyright (c) 2000-2013 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 OrgGroupRolePK implements Comparable<OrgGroupRolePK>, Serializable {
026            public long organizationId;
027            public long groupId;
028            public long roleId;
029    
030            public OrgGroupRolePK() {
031            }
032    
033            public OrgGroupRolePK(long organizationId, long groupId, long roleId) {
034                    this.organizationId = organizationId;
035                    this.groupId = groupId;
036                    this.roleId = roleId;
037            }
038    
039            public long getOrganizationId() {
040                    return organizationId;
041            }
042    
043            public void setOrganizationId(long organizationId) {
044                    this.organizationId = organizationId;
045            }
046    
047            public long getGroupId() {
048                    return groupId;
049            }
050    
051            public void setGroupId(long groupId) {
052                    this.groupId = groupId;
053            }
054    
055            public long getRoleId() {
056                    return roleId;
057            }
058    
059            public void setRoleId(long roleId) {
060                    this.roleId = roleId;
061            }
062    
063            @Override
064            public int compareTo(OrgGroupRolePK pk) {
065                    if (pk == null) {
066                            return -1;
067                    }
068    
069                    int value = 0;
070    
071                    if (organizationId < pk.organizationId) {
072                            value = -1;
073                    }
074                    else if (organizationId > pk.organizationId) {
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            @Override
117            public boolean equals(Object obj) {
118                    if (this == obj) {
119                            return true;
120                    }
121    
122                    if (!(obj instanceof OrgGroupRolePK)) {
123                            return false;
124                    }
125    
126                    OrgGroupRolePK pk = (OrgGroupRolePK)obj;
127    
128                    if ((organizationId == pk.organizationId) && (groupId == pk.groupId) &&
129                                    (roleId == pk.roleId)) {
130                            return true;
131                    }
132                    else {
133                            return false;
134                    }
135            }
136    
137            @Override
138            public int hashCode() {
139                    return (String.valueOf(organizationId) + String.valueOf(groupId) +
140                    String.valueOf(roleId)).hashCode();
141            }
142    
143            @Override
144            public String toString() {
145                    StringBundler sb = new StringBundler(15);
146    
147                    sb.append(StringPool.OPEN_CURLY_BRACE);
148    
149                    sb.append("organizationId");
150                    sb.append(StringPool.EQUAL);
151                    sb.append(organizationId);
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    }