I want to limit the maximum size of a HashMap to take metrics on a variety of hashing algorithms that I\'m implementing. I looked at the loadfactor in one of
Sometimes simpler is better.
public class InstrumentedHashMap implements Map {
private Map map;
public InstrumentedHashMap() {
map = new HashMap();
}
public boolean put(K key, V value) {
if (map.size() >= MAX && !map.containsKey(key)) {
return false;
} else {
map.put(key, value);
return true;
}
}
...
}