-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountingMapData.java
More file actions
61 lines (51 loc) · 1.45 KB
/
CountingMapData.java
File metadata and controls
61 lines (51 loc) · 1.45 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package btp.oneP;
import java.util.AbstractMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
public class CountingMapData extends AbstractMap<Integer,String>{
public static void main(String...args){
System.out.println(new CountingMapData(60));
}
private int size;
private static String[] chars = "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z".split(" ");
public CountingMapData(int size){
this.size = size<0?0:size;
}
private static class Entry implements Map.Entry<Integer, String>{
int index;
Entry(int index){
this.index = index;
}
public boolean equals(Object o){
return Integer.valueOf(index).equals(o);
}
@Override
public Integer getKey() {
// TODO Auto-generated method stub
return index;
}
@Override
public String getValue() {
// TODO Auto-generated method stub
return chars[index%chars.length]+Integer.toString(index/chars.length);
}
@Override
public String setValue(String value) {
// TODO Auto-generated method stub
return null;
}
public int hashCode(){
return Integer.valueOf(index).hashCode();
}
}
@Override
public Set<java.util.Map.Entry<Integer, String>> entrySet() {
// TODO Auto-generated method stub
Set<Map.Entry<Integer, String>> entries = new LinkedHashSet<Map.Entry<Integer,String>>();
for(int i=0;i<size;i++){
entries.add(new Entry(i));
}
return entries;
}
}