/*
 * $Id: CaseIndependentComparator.java,v 1.2 2005/09/15 23:16:44 marbobo Exp $
 *
 * Copyright (c) Siemens AG 2008 
 *           (c) Universität Paderborn 2008 
 * Licensed under EUPL 1.1. 
 *
 * $Log: CaseIndependentComparator.java,v $
 * Revision 1.2  2005/09/15 23:16:44  marbobo
 * + Sprachabhängiges Sortieren implementiert
 *
 * Revision 1.1  2004/03/07 20:02:52  bigmac
 * *** empty log message ***
 *
 * Revision 1.1  2003/11/05 00:26:43  koppy
 * Initiale Version
 *
 *
 */
package vkc.util.sort;

import java.text.CollationKey;
import java.text.Collator;
import java.util.Comparator;

import vkc.db.serializer.VKCLanguageSerializer;
import vkc.util.VKCStringUtils;


/**
 * Komparator-Klasse zum Sortieren von Objekten
 * unabhgg. davon ob die String-Representation eines
 * Objektes groß- oder kleingeschrieben wird
 * 
 * @author koppy
 */
public class CaseIndependentComparator implements Comparator{
	private static final Collator collator = Collator.getInstance(VKCLanguageSerializer.getDefaultLanguage().getLocale());

	/**
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
	 */
	public int compare(Object o1, Object o2) {			
    	CollationKey key1 = collator.getCollationKey(VKCStringUtils.decodeXmlEntities(o1.toString()));
    	CollationKey key2 = collator.getCollationKey(VKCStringUtils.decodeXmlEntities(o2.toString()));
    	
    	return key1.compareTo(key2);
					
	}
}