Package: AlternativeTraceNode

AlternativeTraceNode

nameinstructionbranchcomplexitylinemethod
AlternativeTraceNode()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
get(int)
M: 3 C: 55
95%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 1 C: 11
92%
M: 0 C: 1
100%
getTests()
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
size()
M: 0 C: 71
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
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.interpreter.traces;
25:
26: import java.util.HashMap;
27: import java.util.List;
28: import java.util.Map;
29: import java.util.Vector;
30:
31: import org.overture.interpreter.traces.util.LazyTestSequence;
32: import org.overture.interpreter.traces.util.Pair;
33:
34: public class AlternativeTraceNode extends TraceNode implements
35:                 IIterableTraceNode
36: {
37:         public List<TraceNode> alternatives;
38:
39:         private Map<Integer, Pair<Integer, Integer>> indics;
40:
41:         public AlternativeTraceNode()
42:         {
43:                 this.alternatives = new Vector<TraceNode>();
44:         }
45:
46:         @Override
47:         public CallSequence get(int index)
48:         {
49:•                if (indics == null)
50:                 {
51:                         size();
52:                 }
53:
54:                 Pair<Integer, Integer> v = indics.get(index);
55:                 
56:                 TraceNode tmp = alternatives.get(v.first);
57:                 
58:•                if(tmp instanceof IIterableTraceNode)
59:                 {
60:                         IIterableTraceNode in = (IIterableTraceNode) tmp;
61:                         
62:                         CallSequence callSeq = tmp.getVariables();
63:                         callSeq.addAll(in.get(v.second));
64:                         
65:                         return callSeq;
66:                 }else
67:                 {
68:                         CallSequence callSeq = tmp.getVariables();
69:                         callSeq.addAll(tmp.getTests().get(v.second));
70:                         
71:                         return callSeq;
72:                 }
73:         }
74:
75:         @Override
76:         public TestSequence getTests()
77:         {
78:                 return new LazyTestSequence(this);
79:         }
80:         
81:         @Override
82:         public int size()
83:         {
84:                 int size = 0;
85:                 
86:•                if(indics!=null)
87:                 {
88:                         return indics.size();
89:                 }
90:                 
91:                 indics = new HashMap<Integer, Pair<Integer, Integer>>();
92:                 int k=0;
93:                 
94:•                for (TraceNode node : alternatives)
95:                 {
96:                         // Alternatives within an alternative are just like larger alts,
97:                         // so we add all the lower alts to the list...
98:                         
99:                         int s = 0;
100:•                        if(node instanceof IIterableTraceNode)
101:                         {
102:                                 s = ((IIterableTraceNode)node).size();
103:                         }else
104:                         {
105:                                 s = node.getTests().size();
106:                         }
107:                         
108:•                        for (int i = 0; i < s; i++)
109:                         {
110:                                 indics.put(size+i, new Pair<Integer,Integer>(k,i));
111:                         }
112:                         
113:                         size+=s;
114:                         k++;
115:                 }
116:                 return size;
117:         }
118:
119:         @Override
120:         public String toString()
121:         {
122:                 StringBuilder sb = new StringBuilder();
123:                 sb.append("(");
124:                 String sep = "";
125:
126:•                for (TraceNode node : alternatives)
127:                 {
128:                         sb.append(sep);
129:                         sb.append(node.toString());
130:                         sep = " | ";
131:                 }
132:
133:                 sb.append(")");
134:                 return sb.toString();
135:         }
136: }