Java tutorial
/*$Id: AuditEntryComparator.java 11122 2008-10-29 03:55:31Z jens $*/ /* **************************************************************************** * * * (c) Copyright 2004 ABM-utvikling * * * * This program is free software; you can redistribute it and/or modify it * * under the terms of the GNU General Public License as published by the * * Free Software Foundation; either version 2 of the License, or (at your * * option) any later version. * * * * This program is distributed in the hope that it will be useful, but * * WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * * Public License for more details. http://www.gnu.org/licenses/gpl.html * * * **************************************************************************** */ package no.abmu.common; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import java.util.Comparator; /** * AuditEntryComparator. * * @author Erik Romson, erik@zenior.no * @author $Author:jens $ * @version $Rev: 11122 $ * $Date: 2008-10-29 04:55:31 +0100 (Wed, 29 Oct 2008) $ * copyright ABM-Utvikling * @since 2004-12-09 (Rev. 210) */ public class AuditEntryComparator implements Comparator { private static final Log logger = (Log) LogFactory.getLog(AuditEntryComparator.class); public int compare(Object o1, Object o2) { if (o1 == o2) { return 0; } if (!(o1 instanceof AuditEntry)) { return 1; } if (!(o2 instanceof AuditEntry)) { return 1; } final AuditEntry auditEntry1 = (AuditEntry) o1; final AuditEntry auditEntry2 = (AuditEntry) o2; if ((auditEntry1 == null) && (auditEntry1.getPointInTime() != null) && ((auditEntry2 == null) && (auditEntry2.getPointInTime() != null))) { return auditEntry1.getPointInTime().equals(auditEntry2.getPointInTime()) ? -1 : auditEntry1.getPointInTime().compareTo(auditEntry2.getPointInTime()); } else { return -1; } } }