Mercurial > hg > Members > kono > jpf-core
comparison 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 |
comparison
equal
deleted
inserted
replaced
19:9fea3d8da9aa | 20:b1790909ebb1 |
---|---|
23 | 23 |
24 /** | 24 /** |
25 * an abstract class that creates Event trees | 25 * an abstract class that creates Event trees |
26 * | 26 * |
27 * While there is no need to provide specialized Event types or additional event | 27 * While there is no need to provide specialized Event types or additional event |
28 * constructors, concrete subclasses have to provide a createEventTree() implementation. | 28 * constructors, concrete subclasses have to provide a createRoot() implementation. |
29 * | 29 * |
30 * A typical implementation looks like this | 30 * A typical implementation looks like this |
31 * | 31 * |
32 * public Event createEventTree1() { | 32 * class MyTree extends EventTree { |
33 * return sequence( | 33 * @Override |
34 * public Event createRoot() { | |
35 * return sequence( | |
36 * event("a"), | |
37 * alternatives( | |
38 * event("1"), | |
39 * iteration(2, | |
40 * event("x") | |
41 * ) | |
42 * ), | |
43 * event("b") | |
44 * ); | |
45 * } | |
46 * } | |
47 * | |
48 * or alternatively | |
49 * class MyTree extends EventTree { | |
50 * MyTree(){ | |
51 * root = sequence( | |
52 * event("a"), | |
53 * alternative( | |
54 * event("1), | |
55 * event("2") | |
56 * ) | |
57 * ); | |
58 * } | |
59 * } | |
60 * | |
61 * or alternatively as an anonymous class | |
62 * | |
63 * EventTree myTree = new EventTree( | |
64 * sequence( | |
34 * event("a"), | 65 * event("a"), |
35 * alternatives( | 66 * alternatives( |
36 * event("1"), | 67 * event("1"), |
37 * iteration(2, | 68 * iteration(2, |
38 * event("x") | 69 * event("x") |
39 * ) | 70 * ) |
40 * ), | 71 * ), |
41 * event("b") | 72 * event("b") |
73 * ) | |
42 * ); | 74 * ); |
43 * } | 75 * |
44 */ | 76 */ |
45 public class EventTree extends EventConstructor { | 77 public class EventTree implements EventConstructor { |
46 | 78 |
47 public static final String CONFIG_KEY = "event.tree.class"; | 79 public static final String CONFIG_KEY = "event.tree.class"; |
48 | 80 |
49 protected Event root; | 81 protected Event root; |
50 | 82 |
51 /** | 83 /** |
52 * this is our purpose in life, which has to be provided by concrete subclasses | 84 * this is our purpose in life, which has to be provided by concrete subclasses |
53 */ | 85 */ |
54 public Event createEventTree() { | 86 public Event createRoot() { |
55 // nothing here, needs to be overridden by subclass to populate tree | 87 // nothing here, needs to be overridden by subclass to populate tree |
56 return null; | 88 return null; |
57 } | 89 } |
58 | 90 |
59 protected EventTree (){ | 91 protected EventTree () { |
60 root = createEventTree(); | 92 root = createRoot(); |
61 } | 93 } |
62 | 94 |
63 protected EventTree (Event root){ | 95 protected EventTree (Event root){ |
64 this.root = root; | 96 this.root = root; |
65 } | 97 } |