/** * 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; //resys-imports import no.dusken.common.model.Person; import org.pegadi.model.Article; import java.util.Comparator; /** * Compares two articles by the name of their photographer.. * (and that only, does not fail back to ID should the names match). * * @author <a href="mailto:jb@underdusken.no">Jørgen Binningsbø</a> * @version $Id$ * @see Comparator */ public class ArticleByPhotographerComparator implements Comparator { /** * The name of the comparator */ protected String name; /** * Creates a new comparator with the given name. */ public ArticleByPhotographerComparator(String name) { this.name = name; } /** * Creates an new comparator with the default name. */ public ArticleByPhotographerComparator() { this.name = "Photographer"; } public int compare(Object o1, Object o2) { int lastCmp; Article art1 = (Article) o1; Article art2 = (Article) o2; Person photographer1 = art1.getPhotographer(); Person photographer2 = art2.getPhotographer(); if (photographer1 == null & photographer2 == null) lastCmp = 0; else if (photographer1 == null) lastCmp = 1; else if (photographer2 == null) lastCmp = -1; else lastCmp = art1.getPhotographer().getName().compareTo(art2.getPhotographer().getName()); return lastCmp; } public String toString() { return name; } }