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.search;
016    
017    import java.util.Comparator;
018    
019    /**
020     * @author Preston Crary
021     */
022    public class IndexerClassNameComparator implements Comparator<Indexer<?>> {
023    
024            public IndexerClassNameComparator() {
025                    this(false);
026            }
027    
028            public IndexerClassNameComparator(boolean ascending) {
029                    _ascending = ascending;
030            }
031    
032            @Override
033            public int compare(Indexer<?> indexer1, Indexer<?> indexer2) {
034                    String className1 = indexer1.getClassName();
035                    String className2 = indexer2.getClassName();
036    
037                    int value = className1.compareTo(className2);
038    
039                    if (_ascending) {
040                            return value;
041                    }
042    
043                    return -value;
044            }
045    
046            public boolean isAscending() {
047                    return _ascending;
048            }
049    
050            private final boolean _ascending;
051    
052    }