KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > gnu > expr > Special


1 package gnu.expr;
2 import gnu.text.Printable;
3 import java.io.*;
4 import gnu.lists.Consumer;
5
6 /** A class of special one-of-a-kind builtin values. */
7
8 public class Special extends Object JavaDoc implements Printable, Externalizable
9 {
10   private String JavaDoc name;
11
12   public static final Special undefined = new Special("undefined");
13   public static final Special optional = new Special("optional");
14   public static final Special rest = new Special("rest");
15   public static final Special key = new Special("key");
16   public static final Special dfault = new Special("default");
17   public static final Object JavaDoc eof = gnu.lists.Sequence.eofValue;
18   // Also:
19
// #!void is the same as Values.Empty.
20
// #!null is Java null.
21

22   public Special ()
23   {
24   }
25
26   private Special (String JavaDoc n)
27   {
28     name = new String JavaDoc(n);
29   }
30
31   public static Special make (String JavaDoc name)
32   {
33     if (name == "optional") return optional;
34     if (name == "rest") return rest;
35     if (name == "key") return key;
36     if (name == "default") return dfault;
37     return new Special(name);
38   }
39
40   public int hashCode () { return name.hashCode (); }
41
42   public final String JavaDoc toString()
43   {
44     return "#!" + name;
45   }
46
47   public void print (Consumer out)
48   {
49     out.write("#!");
50     out.write(name);
51   }
52
53   /**
54    * @serialData Write the keword name (without colons) using writeUTF.
55    */

56
57   public void writeExternal(ObjectOutput out) throws IOException
58   {
59     out.writeUTF(name);
60   }
61
62   public void readExternal(ObjectInput in)
63     throws IOException, ClassNotFoundException JavaDoc
64   {
65     name = in.readUTF();
66   }
67
68   public Object JavaDoc readResolve() throws ObjectStreamException
69   {
70     return make(name);
71   }
72 }
73
Popular Tags