diff src/main/gov/nasa/jpf/util/event/EventTree.java @ 20:b1790909ebb1

changed EventForest to derive from EventTree, which kills three birds with one stone - guaranteeing there is a default tree, being able to initialize a concrete forest with one method (createRoot), and being able to use both EventTree and EventForest with a ForestCGFactory, i.e. without changes to the config other than the event tree class name slight refactoring of EventTree (createTree() -> createRoot()) to make it more obvious how the result is used
author Peter Mehlitz <pcmehlitz@gmail.com>
date Mon, 06 Apr 2015 12:08:03 -0700
parents b920e6b1be83
children
line wrap: on
line diff
--- a/src/main/gov/nasa/jpf/util/event/EventTree.java	Wed Apr 01 12:14:15 2015 -0700
+++ b/src/main/gov/nasa/jpf/util/event/EventTree.java	Mon Apr 06 12:08:03 2015 -0700
@@ -25,24 +25,56 @@
  * an abstract class that creates Event trees
  * 
  * While there is no need to provide specialized Event types or additional event 
- * constructors, concrete subclasses have to provide a createEventTree() implementation.
+ * constructors, concrete subclasses have to provide a createRoot() implementation.
  * 
  * A typical implementation looks like this
- * 
- *   public Event createEventTree1() {
- *     return sequence(
+ *
+ *   class MyTree extends EventTree {
+ *     @Override
+ *     public Event createRoot() {
+ *       return sequence(
+ *               event("a"),
+ *               alternatives(
+ *                       event("1"),
+ *                       iteration(2,
+ *                               event("x")
+ *                       )
+ *               ),
+ *               event("b")
+ *       );
+ *     }
+ *   }
+ *
+ *   or alternatively
+ *   class MyTree extends EventTree {
+ *     MyTree(){
+ *       root = sequence(
+ *                 event("a"),
+ *                    alternative(
+ *                       event("1),
+ *                       event("2")
+ *                 )
+ *              );
+ *     }
+ *   }
+ *
+ *   or alternatively as an anonymous class
+ *
+ *     EventTree myTree = new EventTree(
+ *         sequence(
  *             event("a"),
  *             alternatives(
- *                     event("1"),
- *                     iteration(2,
- *                             event("x")
- *                     )
+ *                 event("1"),
+ *                 iteration(2,
+ *                     event("x")
+ *                 )
  *             ),
  *             event("b")
+ *         )
  *     );
- *   }
+ *
  */
-public class EventTree extends EventConstructor {
+public class EventTree implements EventConstructor {
   
   public static final String CONFIG_KEY = "event.tree.class";
   
@@ -51,13 +83,13 @@
   /**
    * this is our purpose in life, which has to be provided by concrete subclasses 
    */
-  public Event createEventTree() {
+  public Event createRoot() {
     // nothing here, needs to be overridden by subclass to populate tree
     return null;
   }
 
-  protected EventTree (){
-    root = createEventTree();
+  protected EventTree () {
+    root = createRoot();
   }
 
   protected EventTree (Event root){