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.Resource;
019    
020    /**
021     * @author Alexander Chow
022     */
023    public class ResourceComparator extends OrderByComparator {
024    
025            public static final String ORDER_BY_DESC = "Resource_.resourceId DESC";
026    
027            public static final String[] ORDER_BY_FIELDS = {"resourceId"};
028    
029            @Override
030            public int compare(Object obj1, Object obj2) {
031                    Resource resource1 = (Resource)obj1;
032                    Resource resource2 = (Resource)obj2;
033    
034                    long resourceId1 = resource1.getResourceId();
035                    long resourceId2 = resource2.getResourceId();
036    
037                    if (resourceId1 > resourceId2) {
038                            return -1;
039                    }
040                    else if (resourceId1 < resourceId2) {
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    }