001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.util.comparator;
016    
017    import com.liferay.portal.kernel.util.OrderByComparator;
018    import com.liferay.portal.model.Resource;
019    
020    /**
021     * @author Alexander Chow
022     */
023    public class ResourceComparator extends OrderByComparator {
024    
025            public static String ORDER_BY_DESC = "resourceId DESC";
026    
027            public static String[] ORDER_BY_FIELDS = {"resourceId"};
028    
029            public int compare(Object obj1, Object obj2) {
030                    Resource resource1 = (Resource)obj1;
031                    Resource resource2 = (Resource)obj2;
032    
033                    long resourceId1 = resource1.getResourceId();
034                    long resourceId2 = resource2.getResourceId();
035    
036                    if (resourceId1 > resourceId2) {
037                            return -1;
038                    }
039                    else if (resourceId1 < resourceId2) {
040                            return 1;
041                    }
042                    else {
043                            return 0;
044                    }
045            }
046    
047            public String getOrderBy() {
048                    return ORDER_BY_DESC;
049            }
050    
051            public String[] getOrderByFields() {
052                    return ORDER_BY_FIELDS;
053            }
054    
055            public boolean isAscending() {
056                    return false;
057            }
058    
059    }