001    /**
002     * Copyright (c) 2000-2012 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.model;
016    
017    import java.io.Serializable;
018    
019    /**
020     * @author Brian Wing Shun Chan
021     * @author Jorge Ferrer
022     */
023    public class PermissionDisplay
024            implements Comparable<PermissionDisplay>, Serializable {
025    
026            public PermissionDisplay(
027                    Permission permission, Resource resource, String portletName,
028                    String portletLabel, String modelName, String modelLabel,
029                    String actionId, String actionLabel) {
030    
031                    _permission = permission;
032                    _resource = resource;
033                    _portletName = portletName;
034                    _portletLabel = portletLabel;
035                    _modelName = modelName;
036                    _modelLabel = modelLabel;
037                    _actionId = actionId;
038                    _actionLabel = actionLabel;
039            }
040    
041            public int compareTo(PermissionDisplay permissionDisplay) {
042                    int value = getPortletLabel().compareTo(
043                            permissionDisplay.getPortletLabel());
044    
045                    if (value == 0) {
046                            value = getModelLabel().compareTo(
047                                    permissionDisplay.getModelLabel());
048    
049                            if (value == 0) {
050                                    value = getActionLabel().compareTo(
051                                            permissionDisplay.getActionLabel());
052                            }
053                    }
054    
055                    return value;
056            }
057    
058            @Override
059            public boolean equals(Object obj) {
060                    if (obj == null) {
061                            return false;
062                    }
063    
064                    if (!(obj instanceof PermissionDisplay)) {
065                            return false;
066                    }
067    
068                    PermissionDisplay permissionDisplay = (PermissionDisplay)obj;
069    
070                    if (_portletName.equals(permissionDisplay.getPortletName()) &&
071                            _modelName.equals(permissionDisplay.getModelName()) &&
072                            _actionId.equals(permissionDisplay.getActionId())) {
073    
074                            return true;
075                    }
076                    else {
077                            return false;
078                    }
079            }
080    
081            public String getActionId() {
082                    return _actionId;
083            }
084    
085            public String getActionLabel() {
086                    return _actionLabel;
087            }
088    
089            public String getModelLabel() {
090                    return _modelLabel;
091            }
092    
093            public String getModelName() {
094                    return _modelName;
095            }
096    
097            public Permission getPermission() {
098                    return _permission;
099            }
100    
101            public String getPortletLabel() {
102                    return _portletLabel;
103            }
104    
105            public String getPortletName() {
106                    return _portletName;
107            }
108    
109            public Resource getResource() {
110                    return _resource;
111            }
112    
113            @Override
114            public int hashCode() {
115                    return _portletName.concat(_modelName).concat(_actionId).hashCode();
116            }
117    
118            private String _actionId;
119            private String _actionLabel;
120            private String _modelLabel;
121            private String _modelName;
122            private Permission _permission;
123            private String _portletLabel;
124            private String _portletName;
125            private Resource _resource;
126    
127    }