// get() works as expected (calculating the element on demand).
// containsKey(), entrySet(), size() etc. only refer to the elements
// already made.
// Also allows put().
// Not synchronized
sclass AutoMap extends AbstractMap {
Map map = new HashMap;
IF1 f;
*() {}
*(IF1 *f) {}
*(IF0 f) { this.f = if0ToIF1(f); }
*(Class c) { this.f = a -> nu(c); }
public B get(O a) {
if (map.containsKey(a))
ret map.get(a);
cast a to A;
B b = f.get(a);
map.put(a, b);
ret b;
}
// unclear semantics
public bool containsKey(O a) {
ret map.containsKey(a);
}
public Set> entrySet() {
ret map.entrySet();
}
public int size() { ret map.size(); }
public B put(A a, B b) {
ret map.put(a, b);
}
}