001    /**
002     * Copyright (c) 2000-present 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.kernel.util;
016    
017    /**
018     * @author Shuyang Zhou
019     */
020    public abstract class OrderByComparatorAdapter<T, V>
021            extends OrderByComparator<T> {
022    
023            public OrderByComparatorAdapter(OrderByComparator<V> orderByComparator) {
024                    this._orderByComparator = orderByComparator;
025            }
026    
027            public abstract V adapt(T t);
028    
029            @Override
030            public int compare(T o1, T o2) {
031                    return _orderByComparator.compare(adapt(o1), adapt(o2));
032            }
033    
034            public OrderByComparator<V> getAdaptedOrderByComparator() {
035                    return _orderByComparator;
036            }
037    
038            @Override
039            public String getOrderBy() {
040                    return _orderByComparator.getOrderBy();
041            }
042    
043            @Override
044            public String[] getOrderByConditionFields() {
045                    return _orderByComparator.getOrderByConditionFields();
046            }
047    
048            @Override
049            public Object[] getOrderByConditionValues(Object obj) {
050                    return _orderByComparator.getOrderByConditionValues(obj);
051            }
052    
053            @Override
054            public String[] getOrderByFields() {
055                    return _orderByComparator.getOrderByFields();
056            }
057    
058            @Override
059            public boolean isAscending() {
060                    return _orderByComparator.isAscending();
061            }
062    
063            @Override
064            public boolean isAscending(String field) {
065                    return _orderByComparator.isAscending(field);
066            }
067    
068            @Override
069            public String toString() {
070                    return _orderByComparator.toString();
071            }
072    
073            private final OrderByComparator<V> _orderByComparator;
074    
075    }