import java.util.Comparator;
import java.util.Set;
import java.util.TreeMap;


public class MapaOrdenado {
 
    public static void main(String a[]){
        
        //Comparacion por Nombre (String comparison)
    
        TreeMap<Empleado,String> tm = new TreeMap<Empleado, String>(new ComparaNombre());
        tm.put(new Empleado("Ramom",3000), "RAM");
        tm.put(new Empleado("Juan",6000), "JOHN");
        tm.put(new Empleado("Critina",2000), "CRISH");
        tm.put(new Empleado("Tomas",2400), "TOM");
        Set<Empleado> keys = tm.keySet();
        for(Empleado key:keys){
            System.out.println(key+" ==> "+tm.get(key));
        }
        System.out.println("===================================");
        
        //Comparacion por salario
        
        TreeMap<Empleado,String> trmap = new TreeMap<Empleado, String>(new ComparaSalario());
        trmap.put(new Empleado("Ramon",3000), "RAM");
        trmap.put(new Empleado("Juan",6000), "JOHN");
        trmap.put(new Empleado("Cristina",2000), "CRISH");
        trmap.put(new Empleado("Tomas",2400), "TOM");
        Set<Empleado> ks = trmap.keySet();
        for(Empleado key:ks){
            System.out.println(key+" ==> "+trmap.get(key));
        }
    }
}
 
class ComparaNombre implements Comparator<Empleado>{
 
    @Override
    public int compare(Empleado e1, Empleado e2) {
        return e1.getNombre().compareTo(e2.getNombre());
    }
}
 
class ComparaSalario implements Comparator<Empleado>{
 
    @Override
    public int compare(Empleado e1, Empleado e2) {
        if(e1.getSalario() > e2.getSalario()){
            return 1;
        } else {
            return -1;
        }
    }
}
 
class Empleado{
     
    private String nombre;
    private float salario;
     
    public Empleado(String n, int s){
        this.nombre = n;
        this.salario = s;
    }
     
    public String getNombre() {
        return nombre;
    }
    
    public float getSalario() {
        return salario;
    }
    
    @Override
    public String toString(){
        return "Nombre: "+this.nombre+"-- Salario: "+this.salario;
    }
}
