-
Notifications
You must be signed in to change notification settings - Fork 12
/
MultiTreeMap.java
28 lines (24 loc) · 965 Bytes
/
MultiTreeMap.java
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
import java.util.TreeMap;
import java.util.Collection;
import java.util.ArrayList;
/***
* Navigable Map that allows multiple entries per key, and has case-insensitive keys, while returning a Tuple that includes the case-sensitive key.
***/
public class MultiTreeMap<V> extends TreeMap<String, Collection<Tuple<String, V>>>{
public Collection<Tuple<String, V>> put(String s, Collection<Tuple<String, V>> val) {
Collection<Tuple<String, V>> old = get(s);
super.put(s.toLowerCase(), val);
return old;
}
public Collection<Tuple<String, V>> get(String s) {
return super.get(s.toLowerCase());
}
public Collection<Tuple<String, V>> putSingle(String s, V val) {
Collection<Tuple<String, V>> t = get(s);
if (t == null) {
t = new ArrayList<Tuple<String, V>>();
}
t.add(new Tuple<String, V>(s, val));
return super.put(s.toLowerCase(), t);
}
}