1 package cz.cuni.amis.pogamut.sposh.engine;
2
3 import java.util.ArrayList;
4
5
6
7
8 class StackElement<T extends ElementExecutor> {
9
10 public final String name;
11 public final Class clazz;
12 public final T executor;
13
14 StackElement(Class clazz, String name, T executor) {
15 this.clazz = clazz;
16 this.name = name;
17 this.executor = executor;
18 }
19
20 @Override
21 public String toString() {
22 return "StackElement[" + clazz.getSimpleName() + ":" + name + ":" + executor + "]";
23 }
24
25 T getExecutor() {
26 return executor;
27 }
28 }
29
30
31
32
33
34
35 final class ElementStackTrace extends ArrayList<StackElement> {
36
37 public void push(StackElement element) {
38 add(element);
39 }
40
41 public StackElement pop() {
42 if (size() == 0) return null;
43 return remove(size()-1);
44 }
45
46 public StackElement peek() {
47 if (size() == 0) return null;
48 return get(size()-1);
49 }
50
51 public void removeAllElements() {
52 clear();
53 }
54
55
56
57
58
59
60
61
62 public void cutDownToIncluding(ElementExecutor executor) {
63 if (executor == null) {
64 removeAllElements();
65 return;
66 }
67 while (size() != 0 && peek().getExecutor() != executor) {
68 pop();
69 }
70 if (size() > 0) pop();
71 }
72
73
74
75
76
77
78
79
80 public void cutDownToExcluding(ElementExecutor executor) {
81 if (executor == null) {
82 removeAllElements();
83 return;
84 }
85 while (size() != 0 && peek().getExecutor() != executor) {
86 pop();
87 }
88
89 }
90 }