Package: SequenceTraceNode

SequenceTraceNode

nameinstructionbranchcomplexitylinemethod
SequenceTraceNode()
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: 69
96%
M: 2 C: 6
75%
M: 2 C: 3
60%
M: 1 C: 15
94%
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: 93
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 23
100%
M: 0 C: 1
100%
toString()
M: 32 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 8 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:
33: public class SequenceTraceNode extends TraceNode implements IIterableTraceNode
34: {
35:         private Map<Integer, Integer[]> indics;
36:
37:         public List<TraceNode> nodes;
38:
39:         public SequenceTraceNode()
40:         {
41:                 this.nodes = new Vector<TraceNode>();
42:         }
43:
44:         @Override
45:         public CallSequence get(int index)
46:         {
47:•                if (indics == null)
48:                 {
49:                         size();
50:                 }
51:                 Integer[] select = indics.get(index);
52:
53:                 CallSequence seq = getVariables();
54:
55:                 List<TestSequence> nodetests = new Vector<TestSequence>();
56:                 int count = nodes.size();
57:
58:                 // TODO not good, poor performance
59:•                for (TraceNode node : nodes)
60:                 {
61:                         TestSequence nt = node.getTests();
62:                         nodetests.add(nt);
63:                 }
64:
65:•                for (int i = 0; i < count; i++)
66:                 {
67:                         TestSequence ith = nodetests.get(i);
68:
69:•                        if (!ith.isEmpty())
70:                         {
71:                                 CallSequence subseq = ith.get(select[i]);
72:                                 seq.addAll(subseq);
73:                         }
74:                 }
75:                 return seq;
76:         }
77:
78:         @Override
79:         public TestSequence getTests()
80:         {
81:                 return new LazyTestSequence(this);
82:         }
83:
84:         @Override
85:         public int size()
86:         {
87:•                if (indics != null)
88:                 {
89:                         return indics.size();
90:                 }
91:
92:                 indics = new HashMap<Integer, Integer[]>();
93:
94:                 List<TestSequence> nodetests = new Vector<TestSequence>();
95:                 int count = nodes.size();
96:                 int[] sizes = new int[count];
97:                 int n = 0;
98:
99:•                for (TraceNode node : nodes)
100:                 {
101:                         TestSequence nt = node.getTests();
102:                         nodetests.add(nt);
103:                         sizes[n++] = nt.size();
104:                 }
105:
106:                 int size = 0;
107:
108:                 Permutor p = new Permutor(sizes);
109:
110:•                while (p.hasNext())
111:                 {
112:                         int[] next = p.next();
113:
114:                         Integer[] select = new Integer[next.length];
115:•                        for (int i = 0; i < next.length; i++)
116:                         {
117:                                 select[i] = next[i];
118:                         }
119:                         indics.put(size, select);
120:                         size++;
121:                 }
122:
123:                 return size;
124:         }
125:
126:         @Override
127:         public String toString()
128:         {
129:                 StringBuilder sb = new StringBuilder();
130:                 String sep = "";
131:
132:•                for (TraceNode node : nodes)
133:                 {
134:                         sb.append(sep);
135:                         sb.append(node.toString());
136:                         sep = "; ";
137:                 }
138:
139:                 return sb.toString();
140:         }
141: }