copyright notices/updates
[sbp.git] / src / edu / berkeley / sbp / Union.java
index 204404d..51002ab 100644 (file)
@@ -1,3 +1,5 @@
+// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
+
 package edu.berkeley.sbp;
 import edu.berkeley.sbp.util.*;
 import edu.berkeley.sbp.*;
@@ -44,6 +46,7 @@ public class Union extends Element implements Iterable<Sequence> {
         return alternatives.contains(s);
     }
 
+    /** iterator over this Union's Sequences */
     public Iterator<Sequence> iterator() {
         viewed = true;
         return alternatives.iterator();
@@ -51,24 +54,32 @@ public class Union extends Element implements Iterable<Sequence> {
 
     /** adds an alternative */
     public void add(Sequence s) {
+        /*
+          FIXME
         if (viewed)
-            throw new RuntimeException("attempt to add a Sequence to a Union that has already been examined");
+            throw new RuntimeException("attempt to add a Sequence to a Union that has already been examined:\n  "+this);
+        */
         if (alternatives.contains(s)) return;
         alternatives.add(s);
     }
 
+    /** adds a one-element sequence */
+    public void add(Element e) {
+        add(Sequence.create(e));
+    }
+
 
     // Epsilon Form //////////////////////////////////////////////////////////////////////////////
 
     // FIXME
-    private Forest.Many epsilonForm = null;
-    Forest epsilonForm() {
-        if (epsilonForm != null) return epsilonForm;
-        epsilonForm = new Forest.Many();
+    //private Forest.Many epsilonForm = null;
+    Forest epsilonForm(Input.Region loc) {
+        //if (epsilonForm != null) return epsilonForm;
+        Forest.Many epsilonForm = new Forest.Many();
         for(Sequence s : this) {
             // FIXME FIXME FIXME
             if (new Walk.Cache().possiblyEpsilon(s))
-                epsilonForm.merge(s.epsilonForm());
+                epsilonForm.merge(s.epsilonForm(loc));
         }
         return epsilonForm;
     }