package cl.maps.utils;

import java.util.Comparator;

import org.mpi.openmind.repository.bo.Entity;
import org.mpi.openmind.repository.bo.utils.EntitySortByNormalizedOwnValue;

import cl.maps.duplex.DuplexKey;
import cl.maps.duplex.DuplexMap;

public class DuplexMapSortByNormalizedOV<V, A, B>  implements Comparator<DuplexKey<A, B>>{
	
	private DuplexMap<V, A, B> dupleMap;
	
	
	public DuplexMapSortByNormalizedOV(DuplexMap<V, A, B> map){
		this.dupleMap = map;
	}
	
	public int compare(DuplexKey<A, B> a, DuplexKey<A, B> b){
		Entity entA = (Entity)dupleMap.get(a);
		Entity entB = (Entity)dupleMap.get(b);
		if(entA == null || entB == null){
			try {
				throw new Exception("Sorting: in comparison a entity was null");	
			} catch (Exception e) {
				e.printStackTrace();
			}
		}	
		return EntitySortByNormalizedOwnValue.compare0(entA, entB);
	}
}