KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > kawa > lang > EqualPat


1 package kawa.lang;
2 import gnu.mapping.*;
3 import java.io.*;
4 import gnu.text.*;
5 import gnu.lists.Consumer;
6
7 /**
8  * A pattern that requires an exact match (using equal?).
9  */

10
11 public class EqualPat extends Pattern implements Printable, Externalizable
12 {
13
14   Object JavaDoc value;
15
16   public EqualPat () { }
17
18   public EqualPat (Object JavaDoc obj) { value = obj; }
19
20   static public EqualPat make (Object JavaDoc obj) { return new EqualPat (obj); }
21
22   public boolean match (Object JavaDoc obj, Object JavaDoc[] vars, int start_vars)
23   {
24     // We should be using Translator's matches routine, but the current
25
// Translator isn't available, so here is a special-purpose kludge.
26
if (value instanceof String JavaDoc && obj instanceof Symbol)
27       obj = ((Symbol) obj).getName();
28     return value.equals (obj);
29   }
30
31   public int varCount () { return 0; }
32
33   public void print (Consumer out)
34   {
35     out.write("#<equals: ");
36     ReportFormat.print(value, out);
37     out.write('>');
38   }
39
40   /**
41    * @serialData Write the value (using writeObject).
42    */

43   public void writeExternal(ObjectOutput out) throws IOException
44   {
45     out.writeObject(value);
46   }
47
48   public void readExternal(ObjectInput in)
49     throws IOException, ClassNotFoundException JavaDoc
50   {
51     value = in.readObject();
52   }
53 }
54
Popular Tags