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.util.comparator;
016    
017    import com.liferay.portal.kernel.util.OrderByComparator;
018    import com.liferay.portal.model.Permission;
019    
020    /**
021     * @author Alexander Chow
022     */
023    public class PermissionComparator extends OrderByComparator {
024    
025            public static final String ORDER_BY_DESC = "Permission_.permissionId DESC";
026    
027            public static final String[] ORDER_BY_FIELDS = {"permissionId"};
028    
029            @Override
030            public int compare(Object obj1, Object obj2) {
031                    Permission perm1 = (Permission)obj1;
032                    Permission perm2 = (Permission)obj2;
033    
034                    long permissionId1 = perm1.getPermissionId();
035                    long permissionId2 = perm2.getPermissionId();
036    
037                    if (permissionId1 > permissionId2) {
038                            return -1;
039                    }
040                    else if (permissionId1 < permissionId2) {
041                            return 1;
042                    }
043                    else {
044                            return 0;
045                    }
046            }
047    
048            @Override
049            public String getOrderBy() {
050                    return ORDER_BY_DESC;
051            }
052    
053            @Override
054            public String[] getOrderByFields() {
055                    return ORDER_BY_FIELDS;
056            }
057    
058            @Override
059            public boolean isAscending() {
060                    return false;
061            }
062    
063    }