/*
 * $Id: ProjectMessageSortFactory.java,v 1.6 2006/10/04 03:15:03 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: ProjectMessageSortFactory.java,v $
 * Revision 1.6  2006/10/04 03:15:03  marbobo
 * + Vollständige Unterstützung für Templates implementiert
 * + Alles von Virtoweb auf ProCoBa umgestellt
 *
 * Revision 1.5  2004/07/20 08:41:36  jonyp
 * added copyright info + cvs log
 *
 *
 */

package vkc.util.sort;

import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import vkc.procoba.project.entities.VKCProjectMessage;

public class ProjectMessageSortFactory {

	public static final int SORT_BY_DATE_UP   = 1;
	public static final int SORT_BY_DATE_DOWN = 2;
	
	private ProjectMessageSortFactory() {
	}
	
	public final static void sort( List l, int mode ){

		if ( l==null ) {
			return;
		}

		switch( mode ) {		

			case SORT_BY_DATE_UP:
				Collections.sort( l, COMP_DATE_DOWN );
				break;
			
			case SORT_BY_DATE_DOWN:
				Collections.sort( l, COMP_DATE_UP );
				break;

		}
	}

	private static final Comparator COMP_DATE_DOWN = new Comparator(  ) {

		public int compare( Object o1, Object o2 )
		{
			Date d1 = ((VKCProjectMessage)o1).getCreationDate();
			Date d2 = ((VKCProjectMessage)o2).getCreationDate();
			
			return d1.compareTo( d2 );
		}
	};

	private static final Comparator COMP_DATE_UP = new Comparator(  ) {

		public int compare( Object o1, Object o2 )
		{
			Date d1 = ((VKCProjectMessage)o1).getCreationDate();
			Date d2 = ((VKCProjectMessage)o2).getCreationDate();
			
			return -d1.compareTo( d2 );
		}
	};
}