01: package kawa.lang;
02:
03: import gnu.mapping.*;
04: import java.io.*;
05: import gnu.text.*;
06: import gnu.lists.Consumer;
07:
08: /**
09: * A pattern that requires an exact match (using equal?).
10: */
11:
12: public class EqualPat extends Pattern implements Printable,
13: Externalizable {
14:
15: Object value;
16:
17: public EqualPat() {
18: }
19:
20: public EqualPat(Object obj) {
21: value = obj;
22: }
23:
24: static public EqualPat make(Object obj) {
25: return new EqualPat(obj);
26: }
27:
28: public boolean match(Object obj, Object[] vars, int start_vars) {
29: // We should be using Translator's matches routine, but the current
30: // Translator isn't available, so here is a special-purpose kludge.
31: if (value instanceof String && obj instanceof Symbol)
32: obj = ((Symbol) obj).getName();
33: return value.equals(obj);
34: }
35:
36: public int varCount() {
37: return 0;
38: }
39:
40: public void print(Consumer out) {
41: out.write("#<equals: ");
42: ReportFormat.print(value, out);
43: out.write('>');
44: }
45:
46: /**
47: * @serialData Write the value (using writeObject).
48: */
49: public void writeExternal(ObjectOutput out) throws IOException {
50: out.writeObject(value);
51: }
52:
53: public void readExternal(ObjectInput in) throws IOException,
54: ClassNotFoundException {
55: value = in.readObject();
56: }
57: }
|