+ public static class Obj extends Basket.Hash implements JS {
+ private static final String[] emptystr = new String[0];
+ private static final Placeholder holder = new Placeholder();
+
+ // HACK: this is hideously, disgustingly ugly.... we need N-ary Hash classes
+ /** entries[index + 0] // key
+ * entries[index + 1] // value
+ * entries[index + 2] // trap
+ */
+
+ protected void entryAdded(int p) {}
+ protected void entryUpdated(int p) {}
+ protected void entryRemoved(int p) {}
+
+ public Obj() { super(3, 4, 0.75F); }
+
+ public JS unclone() { return this; }
+ public InputStream getInputStream() throws IOException, JSExn { throw new JSExn(
+ "object has not associated stream, class ["+ getClass().getName() +"]"); }
+
+ public Object run(Object o) throws Exception { throw new JSExn(
+ "object cannot be called, class ["+ getClass().getName() +"]"); }
+ public void pause() { throw new NotPausableException(); }
+
+ public JS call(JS[] args) throws JSExn { throw new JSExn(
+ "object cannot be called, class ["+ getClass().getName() +"]"); }
+ public JS call(JS method, JS[] args) throws JSExn { throw new JSExn(
+ "method not found: " + JSU.str(method)); }
+ public String[] getFormalArgs() { return emptystr; }
+
+ public Enumeration keys() throws JSExn {
+ return new Enumeration(null) {
+ private int dest = -1, next = -1;
+ public boolean _hasNext() {
+ for (int i = Math.max(0, dest); i < usedslots; i++)
+ if (i > 0 ? entries[i * indexmultiple] != null : true &&
+ entries[i * indexmultiple] != this) { next = i; return true; }
+ return false;
+ }
+ public JS _next() throws JSExn {
+ if (next < 0 && !hasNext()) throw new NoSuchElementException();
+ int index = next; dest = next; next = -1;
+ return (JS)entries[index * indexmultiple];
+ }
+ };
+ }
+ public JS get(JS key) throws JSExn { int i = indexOf(key);
+ return i < 0 ? null : entries[i + 1] instanceof Placeholder ? null : (JS)entries[i + 1]; }
+ public void put(JS key, JS val) throws JSExn {
+ // NOTE: only way value can be stored as null is using declare()
+ int dest = put(indexOf(key), key);
+ if (val == null) entries[dest + 1] = holder;
+ else entries[dest + 1] = val; }
+
+ /*public boolean hasValue(JS key, JS value) {
+ int i = indexOf(key); return i >= 0 && entries[i + 1] != null; }
+ public boolean hasTrap(JS key, JS trap) {
+ int i = indexOf(key); return i >= 0 && entries[i + 2] != null; }*/
+
+ public void declare(JS key) throws JSExn { entries[put(indexOf(key), key) + 1] = null; }
+ public void undeclare(JS key) throws JSExn { remove(indexOf(key)); }
+
+ public JS putAndTriggerTraps(JS key, JS val) throws JSExn {
+ Trap t = null; int i = indexOf(key);
+ if (i >= 0) t = (Trap)entries[i + 2];
+ if (t != null && (t = t.write()) != null) {
+ val = (JS)new Interpreter(t, val, false).run(null);
+ }
+ put(key, val); // HACK: necessary for subclasses overriding put()
+ /*if (i < 0) i = put(i, key);
+ if (val == null) entries[i + 1] = holder;
+ else entries[i + 1] = val;*/
+ return val;
+ }
+ public JS getAndTriggerTraps(JS key) throws JSExn {
+ Trap t = null; int i = indexOf(key);
+ if (i < 0) return get(key); // HACK: necessary for subclasses overriding get()
+ t = (Trap)entries[i + 2];
+ return t == null ? (JS)entries[i + 1] : (JS)new Interpreter(t, null, false).run(null);
+ }
+ public JS justTriggerTraps(JS key, JS val) throws JSExn {
+ Trap t = null; int i = indexOf(key);
+ if (i >= 0) t = (Trap)entries[i + 2];
+ if (t == null || (t = t.write()) == null) return val;
+ return (JS)new Interpreter(t, val, true).run(null);
+ }