/** * Copyright 1999-2009 The Pegadi Team * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.pegadi.articlelist; // pegadi-imports import org.pegadi.model.Article; import java.util.Comparator; /** * A @link{Comparator} for comparing/sorting articles by their ArticleType.<p> * <p/> * The algorithm does not sort on ID if the ArticleTypes match. * * @author <a href="mailto:jb@underdusken.no">Jørgen Binningsbø</a> * @version $Id$ * @see Comparator */ public class ArticleByArticleTypeComparator implements Comparator { /** * The name of the comparator */ protected String name; /** * Creates a new comparator with the given name. */ public ArticleByArticleTypeComparator(String name) { this.name = name; } /** * Creates an new comparator with the default name. */ public ArticleByArticleTypeComparator() { this.name = "Article type"; } public int compare(Object o1, Object o2) { Article art1 = (Article) o1; Article art2 = (Article) o2; return art1.getArticleType().getName().compareTo(art2.getArticleType().getName()); } public String toString() { return name; } }