|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.util.EntryValueComparator
public class EntryValueComparator
Comparator designed for the values of Map entries. This is a somewhat hacked ("overloaded") version of a comparator. But the idea is that you want to be comparing two "values". There are three cases: what you have might either be a Map.Entry, which is compared based on its value, or it might be a key in the Map optionally associated with the comparator, and then comparison is done based on the associated value, or if neither of the above is true, the object is compared as being itself a value. Values must implement Comparable to be used. Options to the comparator allow sorting in normal or reversed order, and for sorting by unsigned magnitude (which works only if the values extend Number.
Example use (sorts Map of counts or Counter with highest first):Map counts = ... // Object key -> Integer/Double count List entries=new ArrayList(counts.entrySet()); Collections.sort(entries, new EntryValueComparator(false));
Constructor Summary | |
---|---|
EntryValueComparator()
Constructs a new EntryValueComparator using ascending (normal) order that works on Map.Entry objects. |
|
EntryValueComparator(boolean ascending)
Constructs a new EntryValueComparator that will sort in the given order and works on Map.Entry objects. |
|
EntryValueComparator(Map m)
Constructs a new EntryValueComparator that will sort keys for the given Map in ascending (normal) order. |
|
EntryValueComparator(Map m,
boolean ascending)
Constructs a new EmptyValueComparator to sort keys or entries of the given map in the given order. |
|
EntryValueComparator(Map m,
boolean ascending,
boolean useMagnitude)
Constructs a new EmptyValueComparator to sort keys or entries of the given map in the given order. |
Method Summary | |
---|---|
int |
compare(Object o1,
Object o2)
Compares the values of the two given Map.Entry objects in the given order. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.util.Comparator |
---|
equals |
Constructor Detail |
---|
public EntryValueComparator()
public EntryValueComparator(boolean ascending)
public EntryValueComparator(Map m)
public EntryValueComparator(Map m, boolean ascending)
m
- Map whose keys are to be sorted, or null if
Map.Entry objects will be sorted.ascending
- whether to sort in ascending (normal) order or
descending (reverse) order. Ascending order is alphabetical, descending
order puts higher numbers first.public EntryValueComparator(Map m, boolean ascending, boolean useMagnitude)
m
- Map whose keys are to be sorted, or null if
Map.Entry objects will be sorted.ascending
- whether to sort in ascending (normal) order or
descending (reverse) order. Ascending order is alphabetical, descending
order puts higher numbers first.useMagnitude
- Sort values for magnitude (absolute value).
This only works if the values stored implement Number, and
their magnitudes are compared according to their double value.Method Detail |
---|
public int compare(Object o1, Object o2)
compare
in interface Comparator
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |