//
// RHState.pfi helper
//
// Keeps a mapping from <object>, <int> ==> <object>
// Used to kludge around binary incompatiblity when native methods are
// involved.
//
helper
// import RFile;
import java.util.Hashtable;
import naccio.library.Check;
public class RHState {
static private Object nullMarker = new Object ();
static private Hashtable fmap = new Hashtable ();
public static void add (Object key, int id, Object val) {
util.Assert.assert (id == 0);
util.Assert.assert (!fmap.contains (key));
if (val == null) {
fmap.put (key, nullMarker);
} else {
fmap.put (key, val);
}
// NCheck.debugMessage ("Add object: " + key + " / " + val);
// can't do this here! util.Assert.showStack ();
}
public static Object getValue (Object key, int id) {
// NCheck.debugMessage ("Get value: " + key);
util.Assert.assert (id == 0);
Object res = fmap.get (key);
if (res == nullMarker) {
// NCheck.debugMessage ("Returns null marker!");
return null;
}
if (res == null) {
NCheck.fatalBug ("Lookup object not found: " + key + " / " +
System.in + " in " + fmap);
}
return res;
}
public static void setValue (Object key, int id, Object val) {
util.Assert.assert (id == 0);
util.Assert.assert (fmap.contains (key));
if (val == null) {
fmap.put (key, nullMarker);
} else {
fmap.put (key, val);
}
// NCheck.debugMessage ("Set value: " + key + " / " + val);
}
}
Naccio Home Page
University of Virginia, Computer Science