Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void sortMap(Map<String, GroupByStatsValues<Double, Double>> map) {
- long startTime = System.currentTimeMillis();
- MaxValueComparator gbvc = new MaxValueComparator(map);
- //CountValueComparator gbvc = new CountValueComparator(map);
- TreeMap<String, GroupByStatsValues<Double, Double>> sorted_map = new TreeMap<String, GroupByStatsValues<Double, Double>>(
- gbvc);
- sorted_map.putAll(map);
- long endTime = System.currentTimeMillis();
- System.out.println("time to sort: " + (endTime - startTime));
- int i = 0;
- for (String s : sorted_map.keySet()) {
- if (i > 10) {
- break;
- } else {
- double x = sorted_map.get(s).getMax();
- if (!sorted_map.containsKey(s)) {
- System.out.println("yello");
- } else {
- System.out.println("key/value: " + s + "/"
- + sorted_map.get(s).getCount());
- i++;
- }
- }
- }
- }
- class CountValueComparator implements Comparator {
- Map<String, GroupByStatsValues<Double, Double>> base;
- public CountValueComparator(
- Map<String, GroupByStatsValues<Double, Double>> base) {
- this.base = base;
- }
- public int compare(Object a, Object b) {
- String aStr = (String) a;
- String bStr = (String) b;
- if (((GroupByStatsValues<Double, Double>) base.get(aStr)).getCount() < ((GroupByStatsValues<Double, Double>) base
- .get(bStr)).getCount()) {
- return 1;
- } else if (((GroupByStatsValues<Double, Double>) base.get(aStr))
- .getCount() == ((GroupByStatsValues<Double, Double>) base
- .get(bStr)).getCount()) {
- return 0;
- } else {
- return -1;
- }
- }
- }
- class MaxValueComparator implements Comparator {
- Map<String, GroupByStatsValues<Double, Double>> base;
- public MaxValueComparator(
- Map<String, GroupByStatsValues<Double, Double>> base) {
- this.base = base;
- }
- public int compare(Object a, Object b) {
- String aStr = (String) a;
- String bStr = (String) b;
- if (((GroupByStatsValues<Double, Double>) base.get(aStr)).getMax() < ((GroupByStatsValues<Double, Double>) base
- .get(bStr)).getMax()) {
- return 1;
- } else if (((GroupByStatsValues<Double, Double>) base.get(aStr))
- .getMax() == ((GroupByStatsValues<Double, Double>) base
- .get(bStr)).getMax()) {
- return 0;
- } else {
- return -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement