01: package gnu.expr;
02:
03: import gnu.text.Printable;
04: import java.io.*;
05: import gnu.lists.Consumer;
06:
07: /** A class of special one-of-a-kind builtin values. */
08:
09: public class Special extends Object implements Printable,
10: Externalizable {
11: private String name;
12:
13: public static final Special undefined = new Special("undefined");
14: public static final Special optional = new Special("optional");
15: public static final Special rest = new Special("rest");
16: public static final Special key = new Special("key");
17: public static final Special dfault = new Special("default");
18: public static final Object eof = gnu.lists.Sequence.eofValue;
19:
20: // Also:
21: // #!void is the same as Values.Empty.
22: // #!null is Java null.
23:
24: public Special() {
25: }
26:
27: private Special(String n) {
28: name = new String(n);
29: }
30:
31: public static Special make(String name) {
32: if (name == "optional")
33: return optional;
34: if (name == "rest")
35: return rest;
36: if (name == "key")
37: return key;
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(Consumer out) {
52: out.write("#!");
53: out.write(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: }
|