IndexedMap.java
package org.microspace.table.column;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import org.microspace.annotation.IndexType;
/**
* @author Gaspar Sinai
* @version 2012-06-02
*/
public class IndexedMap<K,V> {
Map<K,V> map;
IndexType type;
public IndexedMap (IndexType type) {
this.type = type;
switch (type) {
case HASHED:
map = new HashMap<K,V> ();
break;
case SORTED:
map = new TreeMap<K,V> ();
break;
default:
throw new IllegalArgumentException ("Unhandled index type: " + type);
}
}
public V get (K key) {
return map.get (key);
}
public V put (K key, V value) {
return map.put (key, value);
}
public void putAll (IndexedMap<K,V> map) {
this.map.putAll (map.map);
}
public V remove (K key){
return map.remove (key);
}
public int size () {
return map.size();
}
public IndexedSet<K> keySet () {
IndexedSet<K> ret = new IndexedSet<K> (type);
for (K k : map.keySet()) {
ret.add(k);
}
return ret;
}
public Collection<V> values () {
return map.values();
}
public void clear () {
map.clear();
}
}