/*
Copyright 2012-2014 Samuel Gesche

This file is part of the Greek Reuse Toolkit.

The Greek Reuse Toolkit 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 3 of the License, or
(at your option) any later version.

The Greek Reuse Toolkit 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.

You should have received a copy of the GNU General Public License
along with the Greek Reuse Toolkit.  If not, see <http://www.gnu.org/licenses/>.
*/

package fr.cnrs.liris.drim.grt.modele.listes;

import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import fr.cnrs.liris.drim.grt.proc.parsers.Textes;
import fr.cnrs.liris.drim.grt.proc.parsers.Textes;

/**
 *
 * @author sgesche
 */
public class OrdreAlphabetiqueGrec implements Comparator {

    public OrdreAlphabetiqueGrec() {
        
    }
    
    private static Map<String, String> normalisations = new HashMap<>();
    private final static Object jeton = new Object();
    private String normalise(String s) {
        synchronized(jeton) {
            if(!normalisations.containsKey(s)) {
                normalisations.put(s, Textes.normalise(s));
            }
            return normalisations.get(s);
        }
    }
    
    @Override
    public int compare(Object o1, Object o2) {
        String s1 = normalise(o1.toString());
        String s2 = normalise(o2.toString());
        return s1.compareTo(s2);
    }
    
}
