MapValueComparator.java :  » Database-ORM » ProjectJulp » org » julp » util » common » Java Open Source

Java Open Source » Database ORM » ProjectJulp 
ProjectJulp » org » julp » util » common » MapValueComparator.java
package org.julp.util.common;

import java.util.Comparator;
import java.util.Map;
import java.util.Map.Entry;
import java.io.Serializable;

// This class is used to sort Map by value (vs key).
public class MapValueComparator implements Comparator, Serializable {
    
    Map.Entry mapEntry = null;
    public MapValueComparator() {}
    
    public MapValueComparator(Map.Entry mapEntry) {
        this.mapEntry = mapEntry;
    }
        
    public int compare(Object o1, Object o2){
        Object v1 = ((Map.Entry) o1).getValue();
        Object v2 = ((Map.Entry) o2).getValue();
        return ((Comparable) v1).compareTo(v2);
    }
    
    public boolean equals(Object obj) {
        return this.mapEntry.getValue().equals(((Map.Entry) obj).getValue());
    }
}

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.