1 package edu.berkeley.sbp;
4 import java.lang.reflect.*;
5 import java.lang.ref.*;
6 import edu.berkeley.sbp.util.*;
7 import edu.berkeley.sbp.*;
8 import edu.berkeley.sbp.*;
10 /** an element which matches exactly one input token */
11 public abstract class Atom<T> extends Element implements Topology<T> {
13 protected abstract Topology<T> top();
14 public abstract String toString();
15 public StringBuffer toString(StringBuffer sb) { sb.append(this); return sb; }
17 // Topology Thunks //////////////////////////////////////////////////////////////////////////////
19 public Topology<T> unwrap() { return top().unwrap(); }
20 public Topology<T> empty() { return top().empty(); }
21 public boolean contains(T v) { return top().contains(v); }
22 public Topology<T> intersect(Topology<T> t) { return top().intersect(t); }
23 public Topology<T> minus(Topology<T> t) { return top().minus(t); }
24 public Topology<T> union(Topology<T> t) { return top().union(t); }
25 public Topology<T> complement() { return top().complement(); }
26 public boolean disjoint(Topology<T> t) { return top().disjoint(t); }
27 public boolean containsAll(Topology<T> t) { return top().containsAll(t); }
28 public int hashCode() { return top().hashCode(); }
29 public boolean equals(Object o) { return o != null && o instanceof Atom && ((Atom)o).top().equals(top()); }
31 /** if all expressions matching <tt>e</tt> are exactly one token
32 * long, <b>attempt to</b> return an Atom representing that token
33 * (undecidable in general; only works in trivial cases)
35 public static Topology toAtom(Element e) {
36 if (e instanceof Atom) return (Atom)e;
37 if (e instanceof Sequence) return ((Sequence)e).toAtom();
39 for(Sequence s : (Union)e)
40 ret = ret==null ? toAtom(s) : ret.union(s.toAtom());