/*
 * $Id: ProjectInfoSortFactory.java,v 1.3 2004/07/20 08:41:36 jonyp Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: ProjectInfoSortFactory.java,v $
 * Revision 1.3  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.List;

import vkc.view.bean.ProjectInfo;

public class ProjectInfoSortFactory {

	public static final int SORT_BY_NAME_UP   = 1;
	public static final int SORT_BY_NAME_DOWN = 2;
	
	private ProjectInfoSortFactory() {
	}
	
	public final static void sort( List l, int mode ){

		if ( l==null ) {
			return;
		}

		switch( mode ) {		

			case SORT_BY_NAME_DOWN:
				Collections.sort( l, COMP_NAME_DOWN );
				break;
			
			case SORT_BY_NAME_UP:
				Collections.sort( l, COMP_NAME_UP );
				break;

		}
	}

	private static final Comparator COMP_NAME_DOWN = new Comparator(  ) {

		public int compare( Object o1, Object o2 )
		{
			String s1 = ((ProjectInfo)o1).getName();
			String s2 = ((ProjectInfo)o2).getName();
			
			return -s1.compareToIgnoreCase( s2 );
		}
	};

	private static final Comparator COMP_NAME_UP = new Comparator(  ) {

		public int compare( Object o1, Object o2 )
		{
			String s1 = ((ProjectInfo)o1).getName();
			String s2 = ((ProjectInfo)o2).getName();
			
			return s1.compareToIgnoreCase( s2 );
		}
	};
}