helper
import java.util.Hashtable;
import naccio.library.Check;
public class RFileMap {
static private Hashtable fmap = new Hashtable ();
static private boolean inadd = false;
private static RFile add (java.io.File f) {
String path;
if (NCheck.isChecking ()) {
NCheck.noChecking ();
path = f.getAbsolutePath ();
NCheck.resumeChecking ();
} else {
path = f.getAbsolutePath ();
}
RFile rf = new RFile (path);
fmap.put (f, rf);
return rf;
}
private static RFile add (java.io.FileDescriptor f) {
String path;
RFile rf;
if (NCheck.isChecking ()) {
NCheck.noChecking ();
path = f.toString ();
rf = new RFile (path);
NCheck.resumeChecking ();
} else {
path = f.toString ();
rf = new RFile (path);
}
fmap.put (f, rf);
return rf;
}
private static RFile add (String fname) {
RFile rf;
rf = new RFile (fname);
fmap.put (fname, rf);
return rf;
}
public static void addReference (java.io.FileDescriptor d, RFile f) {
fmap.put (d, f);
}
public static RFile lookup (Object f) {
NCheck.assert (f != null);
RFile rf = (RFile) fmap.get (f);
return rf;
}
private static RFile lookupAddReal (java.io.FileDescriptor fd) {
RFile rf = lookup (fd);
if (rf != null) {
return rf;
} else {
if (fd == java.io.FileDescriptor.err
|| fd == java.io.FileDescriptor.in
|| fd == java.io.FileDescriptor.out) {
return null;
} else {
// should do some checking here
// return a marker that barfs on write/read!
return null;
}
}
}
public static RFile lookupAdd (Object f) {
RFile rf = lookup (f);
if (rf == null) {
if (f instanceof java.lang.String) {
rf = add ((java.lang.String) f);
} else if (f instanceof java.io.File) {
rf = add ((java.io.File) f);
} else if (f instanceof java.io.FileDescriptor) {
rf = add ((java.io.FileDescriptor) f);
} else {
NCheck.fatalBug (false, "Bad type: " + f.getClass ());
}
}
return rf;
}
}
Naccio Home Page
University of Virginia, Computer Science