Debian Codegraph @

current/bin/KeyValue.java

raw symbols SCIP
1 package bin;
2
3 import java.util.ArrayList;
4 import java.util.Collections;
5
6 import structures.IntHashMap;
7
8 //Sorts by B descending then A ascending
9 class KeyValue implements Comparable<KeyValue> {
10
11 KeyValue(int a_, int b_){key=a_; value=b_;}
12
13 static ArrayList<KeyValue> toList(IntHashMap map){
14 if(map==null || map.isEmpty()) {return null;}
15 ArrayList<KeyValue> list=new ArrayList<KeyValue>(map.size());
16 int[] keys=map.keys();
17 int[] values=map.values();
18 for(int i=0; i<keys.length; i++) {
19 if(keys[i]!=map.invalid()) {
20 list.add(new KeyValue(keys[i], values[i]));
21 }
22 }
23 Collections.sort(list);
24 return list;
25 }
26
27 @Override
28 public int compareTo(KeyValue o) {
29 if(value!=o.value) {return value>o.value ? -1 : 1;}
30 return key-o.key;
31 }
32
33 int key, value;
34
35 }