001/* 002 * (C) Copyright 2007 Nuxeo SAS (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Nuxeo - initial API and implementation 016 * 017 * $Id: StatementInfoComparator.java 20645 2007-06-17 13:16:54Z sfermigier $ 018 */ 019 020package org.nuxeo.ecm.platform.relations.web; 021 022import java.io.Serializable; 023import java.util.Comparator; 024import java.util.Date; 025 026/** 027 * Statement info comparator to sort relations. 028 * 029 * @author <a href="mailto:at@nuxeo.com">Anahide Tchertchian</a> 030 */ 031public class StatementInfoComparator implements Comparator<StatementInfo>, Serializable { 032 033 private static final long serialVersionUID = -5117909579284277595L; 034 035 public int compare(StatementInfo stmt1, StatementInfo stmt2) { 036 // XXX AT: always compare by modification date for now, will have to be 037 // more pluggable when need to sort tables. 038 Date date1 = stmt1.getModificationDate(); 039 Date date2 = stmt2.getModificationDate(); 040 int result = 0; 041 if (date1 == null) { 042 result = date2 == null ? 0 : -1; 043 } else if (date2 == null) { 044 result = 1; 045 } else { 046 result = date1.compareTo(date2); 047 } 048 return result; 049 } 050 051}