Package: AlternativeTraceNode

AlternativeTraceNode

nameinstructionbranchcomplexitylinemethod
AlternativeTraceNode()
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
add(TraceNode)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
get(int)
M: 58 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%
getTests()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
size()
M: 71 C: 0
0%
M: 8 C: 0
0%
M: 5 C: 0
0%
M: 16 C: 0
0%
M: 1 C: 0
0%
toString()
M: 40 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: *
3: *        Copyright (C) 2008, 2009 Fujitsu Services Ltd.
4: *
5: *        Author: Nick Battle
6: *
7: *        This file is part of VDMJ.
8: *
9: *        VDMJ is free software: you can redistribute it and/or modify
10: *        it under the terms of the GNU General Public License as published by
11: *        the Free Software Foundation, either version 3 of the License, or
12: *        (at your option) any later version.
13: *
14: *        VDMJ is distributed in the hope that it will be useful,
15: *        but WITHOUT ANY WARRANTY; without even the implied warranty of
16: *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: *        GNU General Public License for more details.
18: *
19: *        You should have received a copy of the GNU General Public License
20: *        along with VDMJ. If not, see <http://www.gnu.org/licenses/>.
21: *
22: ******************************************************************************/
23:
24: package org.overture.codegen.runtime.traces;
25:
26: import java.util.HashMap;
27: import java.util.List;
28: import java.util.Map;
29: import java.util.Vector;
30:
31: public class AlternativeTraceNode extends TraceNode
32:                 implements IIterableTraceNode
33: {
34:         public List<TraceNode> alternatives;
35:
36:         public void add(TraceNode node)
37:         {
38:                 alternatives.add(node);
39:         }
40:
41:         private Map<Integer, Pair<Integer, Integer>> indics;
42:
43:         public AlternativeTraceNode()
44:         {
45:                 this.alternatives = new Vector<TraceNode>();
46:         }
47:
48:         @Override
49:         public CallSequence get(int index)
50:         {
51:•                if (indics == null)
52:                 {
53:                         size();
54:                 }
55:
56:                 Pair<Integer, Integer> v = indics.get(index);
57:
58:                 TraceNode tmp = alternatives.get(v.getFirst());
59:
60:•                if (tmp instanceof IIterableTraceNode)
61:                 {
62:                         IIterableTraceNode in = (IIterableTraceNode) tmp;
63:
64:                         CallSequence callSeq = tmp.getVars();
65:                         callSeq.addAll(in.get(v.getSecond()));
66:
67:                         return callSeq;
68:                 } else
69:                 {
70:                         CallSequence callSeq = tmp.getVars();
71:                         callSeq.addAll(tmp.getTests().get(v.getSecond()));
72:
73:                         return callSeq;
74:                 }
75:         }
76:
77:         @Override
78:         public TestSequence getTests()
79:         {
80:                 return new LazyTestSequence(this);
81:         }
82:
83:         @Override
84:         public int size()
85:         {
86:                 int size = 0;
87:
88:•                if (indics != null)
89:                 {
90:                         return indics.size();
91:                 }
92:
93:                 indics = new HashMap<Integer, Pair<Integer, Integer>>();
94:                 int k = 0;
95:
96:•                for (TraceNode node : alternatives)
97:                 {
98:                         // Alternatives within an alternative are just like larger alts,
99:                         // so we add all the lower alts to the list...
100:
101:                         int s = 0;
102:•                        if (node instanceof IIterableTraceNode)
103:                         {
104:                                 s = ((IIterableTraceNode) node).size();
105:                         } else
106:                         {
107:                                 s = node.getTests().size();
108:                         }
109:
110:•                        for (int i = 0; i < s; i++)
111:                         {
112:                                 indics.put(size + i, new Pair<Integer, Integer>(k, i));
113:                         }
114:
115:                         size += s;
116:                         k++;
117:                 }
118:                 return size;
119:         }
120:
121:         @Override
122:         public String toString()
123:         {
124:                 StringBuilder sb = new StringBuilder();
125:                 sb.append("(");
126:                 String sep = "";
127:
128:•                for (TraceNode node : alternatives)
129:                 {
130:                         sb.append(sep);
131:                         sb.append(node.toString());
132:                         sep = " | ";
133:                 }
134:
135:                 sb.append(")");
136:                 return sb.toString();
137:         }
138: }