01: package org.julp.util.common;
02:
03: import java.util.Comparator;
04: import java.util.Map;
05: import java.util.Map.Entry;
06: import java.io.Serializable;
07:
08: // This class is used to sort Map by value (vs key).
09: public class MapValueComparator implements Comparator, Serializable {
10:
11: Map.Entry mapEntry = null;
12:
13: public MapValueComparator() {
14: }
15:
16: public MapValueComparator(Map.Entry mapEntry) {
17: this .mapEntry = mapEntry;
18: }
19:
20: public int compare(Object o1, Object o2) {
21: Object v1 = ((Map.Entry) o1).getValue();
22: Object v2 = ((Map.Entry) o2).getValue();
23: return ((Comparable) v1).compareTo(v2);
24: }
25:
26: public boolean equals(Object obj) {
27: return this .mapEntry.getValue().equals(
28: ((Map.Entry) obj).getValue());
29: }
30: }
|