01: package gnu.expr;
02:
03: import gnu.mapping.Printable;
04: import java.io.*;
05:
06: /** A class of special one-of-a-kind builtin values. */
07:
08: public class Special extends Object implements Printable,
09: Externalizable {
10: private String name;
11:
12: public static Special optional = new Special("optional");
13: public static Special rest = new Special("rest");
14: public static Special key = new Special("key");
15: public static Object eof = gnu.lists.Sequence.eofValue;
16: public static Special dfault = new Special("default");
17:
18: // Also:
19: // #!void is the same as Values.Empty.
20: // #!null is Java null.
21:
22: public Special() {
23: }
24:
25: private Special(String n) {
26: name = new String(n);
27: }
28:
29: public static Object make(String name) {
30: if (name == "optional")
31: return optional;
32: if (name == "rest")
33: return rest;
34: if (name == "key")
35: return key;
36: if (name == "eof")
37: return eof;
38: if (name == "default")
39: return dfault;
40: return new Special(name);
41: }
42:
43: public int hashCode() {
44: return name.hashCode();
45: }
46:
47: public final String toString() {
48: return "#!" + name;
49: }
50:
51: public void print(java.io.PrintWriter ps) {
52: ps.print("#!");
53: ps.print(name);
54: }
55:
56: /**
57: * @serialData Write the keword name (without colons) using writeUTF.
58: */
59:
60: public void writeExternal(ObjectOutput out) throws IOException {
61: out.writeUTF(name);
62: }
63:
64: public void readExternal(ObjectInput in) throws IOException,
65: ClassNotFoundException {
66: name = in.readUTF();
67: }
68:
69: public Object readResolve() throws ObjectStreamException {
70: return make(name);
71: }
72: }
|