package com.poco;


/**
 * Created by caoyan on 12/4/14.
 */
public class AlternationExecution extends SequentialExecution
{
    private Boolean resultBool = false;
	private SRE resultSRE = null;
	
    public AlternationExecution(String modifier) throws PoCoException {
        super(modifier);
    }
 	
    @Override
    public SRE query(Event event) {
    	if (children.size() == 0){
			return null;
		}
		if (!isQueried) {
			if (children.get(0).accepts(event))  {
				resultBool = true;
				resultSRE = children.get(0).query(event);
			} else  {
				resultBool = children.get(1).accepts(event);
				resultSRE = children.get(1).query(event);
			}
			isQueried = true;
			return resultSRE;
		}
		else {
			return resultSRE;
		}
    }

    @Override
    public boolean accepts(Event event) {
    	if (children.size() == 0) {
			return false;
		}
		// The first child of a sequential execution must accept for its parent
		// to accept
		this.query(event);
		return resultBool;
    }
}

@@ -9,18 +9,29 @@
 com.poco
+.PoCoRuntime
 ;
-%0A
 %0A%0A/**%0A *
@@ -130,88 +130,254 @@
 tion
-%0A%7B%0A    private Boolean resultBool = false;%0A%09private SRE resultSRE = null;%0A%09%0A    
+ %7B%0A%09@Override%0A%09public String toString() %7B%0A%09%09return %22AlternationExecution %5BcurrentCursor=%22 + currentCursor%0A%09%09%09%09+ %22, children=%22 + children + %22, isQueried=%22 + isQueried%0A%09%09%09%09+ %22, resultBool=%22 + resultBool + %22, resultSRE=%22 + resultSRE%0A%09%09%09%09+ %22%5D%22;%0A%09%7D%0A%0A%09
 publ
@@ -444,16 +444,10 @@
 n %7B%0A
-        
+%09%09
 supe
@@ -463,21 +463,13 @@
 r);%0A
-    %7D%0A %09%0A    
+%09%7D%0A%0A%09
 @Ove
@@ -470,28 +470,25 @@
 %0A%09@Override%0A
-    
+%09
 public SRE q
@@ -499,36 +499,33 @@
 (Event event) %7B%0A
-    
+%09
 %09if (children.si
@@ -534,16 +534,17 @@
 () == 0)
+ 
 %7B%0A%09%09%09ret
@@ -561,29 +561,8 @@
 %09%09%7D%0A
-%09%09if (!isQueried) %7B%0A%09
 %09%09if
@@ -594,21 +594,19 @@
 (event))
- 
  %7B%0A
-%09
 %09%09%09resul
@@ -619,17 +619,16 @@
 = true;%0A
-%09
 %09%09%09resul
@@ -670,20 +670,17 @@
 ;%0A%09%09
-%09
 %7D else 
- 
 %7B%0A
-%09
 %09%09%09r
@@ -723,17 +723,16 @@
 event);%0A
-%09
 %09%09%09resul
@@ -774,33 +774,10 @@
 ;%0A%09%09
-%09
 %7D%0A
-%09%09%09isQueried = true;%0A%09
 %09%09re
@@ -796,57 +796,13 @@
 RE;%0A
-%09
 %09%7D%0A
+%0A
 %09
-%09else %7B%0A%09%09%09return resultSRE;%0A%09%09%7D%0A    %7D%0A%0A    
 @Ove
@@ -807,20 +807,17 @@
 verride%0A
-    
+%09
 public b
@@ -846,20 +846,17 @@
 vent) %7B%0A
-    
+%09
 %09if (chi
@@ -903,107 +903,113 @@
 %7D%0A%09%09
-// The first child of a sequential execution must accept for its parent%0A%09%09// to accept%0A%09%09this.query
+if(children.get(0).accepts(event)) %7B%0A%09%09%09return true;%0A%09%09%7Delse %7B%0A%09%09%09boolean result =children.get(1).accepts
 (eve
@@ -1013,16 +1013,17 @@
 event);%0A
+%09
 %09%09return
@@ -1033,18 +1033,15 @@
 sult
-Bool;%0A    
+;%0A%09%09%7D%0A%09
 %7D%0A%7D%0A

fix alternation logic