File: KeyValue.java

package info (click to toggle)
bbmap 39.20%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,024 kB
  • sloc: java: 312,743; sh: 18,099; python: 5,247; ansic: 2,074; perl: 96; makefile: 39; xml: 38
file content (35 lines) | stat: -rwxr-xr-x 815 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package bin;

import java.util.ArrayList;
import java.util.Collections;

import structures.IntHashMap;

//Sorts by B descending then A ascending
class KeyValue implements Comparable<KeyValue> {
	
	KeyValue(int a_, int b_){key=a_; value=b_;}
	
	static ArrayList<KeyValue> toList(IntHashMap map){
		if(map==null || map.isEmpty()) {return null;}
		ArrayList<KeyValue> list=new ArrayList<KeyValue>(map.size());
		int[] keys=map.keys();
		int[] values=map.values();
		for(int i=0; i<keys.length; i++) {
			if(keys[i]!=map.invalid()) {
				list.add(new KeyValue(keys[i], values[i]));
			}
		}
		Collections.sort(list);
		return list;
	}
	
	@Override
	public int compareTo(KeyValue o) {
		if(value!=o.value) {return value>o.value ? -1 : 1;}
		return key-o.key;
	}
	
	int key, value;
	
}