Method: getNumber()

1: /*
2: * #%~
3: * Combinatorial Testing
4: * %%
5: * Copyright (C) 2008 - 2014 Overture
6: * %%
7: * This program is free software: you can redistribute it and/or modify
8: * it under the terms of the GNU General Public License as
9: * published by the Free Software Foundation, either version 3 of the
10: * License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public
18: * License along with this program. If not, see
19: * <http://www.gnu.org/licenses/gpl-3.0.html>.
20: * #~%
21: */
22: package org.overture.ide.plugins.combinatorialtesting.views.treeView;
23:
24: import java.io.IOException;
25: import java.util.ArrayList;
26: import java.util.List;
27: import java.util.Vector;
28:
29: import org.overture.ct.utils.TraceHelperNotInitializedException;
30: import org.overture.ct.utils.TraceTestResult;
31: import org.overture.interpreter.traces.Verdict;
32: import org.xml.sax.SAXException;
33:
34: public class TraceTestGroup extends TraceTestTreeNode
35: {
36:         public static final Long GROUP_SIZE = new Long(200);
37:         Long startNumber;
38:         Long stopNumber;
39:         Verdict lastKnownStatus = null;
40:
41:         public TraceTestGroup(Long startNumber, Long stopNumber)
42:         {
43:                 super(null);
44:                 this.startNumber = startNumber;
45:                 this.stopNumber = stopNumber - 1;
46:                 
47:                 children = new ArrayList<ITreeNode>();
48:                 addChild(new NotYetReadyTreeNode());
49:
50:         }
51:         
52:         @Override
53:         public Integer getNumber()
54:         {
55:         return startNumber.intValue();
56:         }
57:
58:         private List<ITreeNode> children;
59:
60:         @Override
61:         public String toString()
62:         {
63:                 return "[" + startNumber + "..." + stopNumber + "]";
64:         }
65:
66:         @Override
67:         public String getName()
68:         {
69:                 return toString();
70:         }
71:
72:
73:         @Override
74:         public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter)
75:         {
76:                 return null;
77:         }
78:
79:         @Override
80:         public void addChild(ITreeNode child)
81:         {
82:                 if (!children.contains(child))
83:                 {
84:                         boolean contains = false;
85:                         for (ITreeNode node : getChildren())
86:                         {
87:
88:                                 if (node.getName().equals(child.getName()))
89:                                 {
90:                                         contains = true;
91:                                 }
92:                         }
93:                         if (!contains)
94:                         {
95:                                 children.add(child);
96:                                 child.setParent(this);
97:                         }
98:                 }
99:         }
100:
101:         public void removeChild(ITreeNode child)
102:         {
103:                 children.remove(child);
104:                 if (child instanceof TraceTestGroup)
105:                 {
106:                         ((TraceTestGroup) child).removeChildern();
107:                 }
108:                 child.setParent(null);
109:         }
110:
111:         @Override
112:         public List<ITreeNode> getChildren()
113:         {
114:                 return children;
115:         }
116:
117:         @Override
118:         public boolean hasChildren()
119:         {
120:                 return stopNumber - startNumber > 0;
121:         }
122:
123:         @Override
124:         public boolean hasChild(String name)
125:         {
126:                 for (ITreeNode node : children)
127:                 {
128:                         if (node.getName().equals(name))
129:                         {
130:                                 return true;
131:                         }
132:
133:                 }
134:                 return false;
135:         }
136:
137:         @Override
138:         public Verdict getStatus()
139:         {
140:                 if (lastKnownStatus == null)
141:                 {
142:                         Verdict status = null;
143:
144:                         for (ITreeNode n : children)
145:                         {
146:                                 if (n instanceof TraceTestTreeNode)
147:                                 {
148:                                         TraceTestTreeNode node = (TraceTestTreeNode) n;
149:                                         status = calculateStatus(status, node.getStatus());
150:                                 }
151:                         }
152:                         lastKnownStatus = status;
153:                 }
154:                 return lastKnownStatus;
155:         }
156:
157:         private Verdict calculateStatus(Verdict status, Verdict nextStatus)
158:         {
159:
160:                 if (nextStatus == Verdict.FAILED)
161:                 {
162:                         return nextStatus;
163:                 } else if (nextStatus == Verdict.INCONCLUSIVE
164:                                 && status != Verdict.FAILED)
165:                 {
166:                         return nextStatus;
167:                 } else if (nextStatus == Verdict.PASSED && status == null)
168:                 {
169:                         status = nextStatus;
170:                 }
171:
172:                 return status;
173:         }
174:
175:         public void loadGroupStatus() throws SAXException, IOException,
176:                         ClassNotFoundException, TraceHelperNotInitializedException
177:         {
178:                 TraceTreeNode t = getTraceParent(this);
179:                 if (t != null)
180:                 {
181:
182:                         List<TraceTestResult> traceStatus = t.getTraceStore().getTraceTests(startNumber.intValue(), stopNumber.intValue());
183:                         Verdict status = null;
184:                         for (TraceTestResult traceTestStatus : traceStatus)
185:                         {
186:                                 lastKnownStatus = calculateStatus(status, traceTestStatus.getStatus());
187:                                 if (lastKnownStatus == Verdict.FAILED)
188:                                 {
189:                                         break;
190:                                 }
191:                         }
192:
193:                 }
194:         }
195:
196:         private void loadTestNodes() throws Exception
197:         {
198:                 TraceTreeNode t = getTraceParent(this);
199:                 if (t != null)
200:                 {
201:
202:                         List<TraceTestResult> traceStatus = t.getTraceStore().getTraceTests(startNumber.intValue(), stopNumber.intValue());
203:
204:                         for (TraceTestResult traceTestStatus : traceStatus)
205:                         {
206:                                 this.addChild(new TraceTestTreeNode(traceTestStatus));
207:                         }
208:                 }
209:         }
210:
211:         private TraceTreeNode getTraceParent(ITreeNode node)
212:         {
213:                 if (node.getParent() == null)
214:                 {
215:                         return null;
216:                 } else if (node.getParent() instanceof TraceTreeNode)
217:                 {
218:                         return (TraceTreeNode) node.getParent();
219:                 } else
220:                 {
221:                         return getTraceParent(node.getParent());
222:                 }
223:         }
224:
225:         public void loadTests() throws Exception
226:         {
227:                 removeChildern();
228:
229:
230:                 Long size = stopNumber - startNumber;
231:
232:                 GroupSizeCalculator gs = new GroupSizeCalculator(size);
233:
234:                 if (!gs.hasGroups())
235:                 {
236:                         loadTestNodes();
237:                 } else
238:                 {
239:
240:                         Long currentCount = startNumber - 1;
241:                         for (int i = 0; i < gs.getNumberOfGroups() - 1; i++)
242:                         {
243:                                 TraceTestGroup group = new TraceTestGroup(currentCount + 1, currentCount
244:                                                 + gs.getGroupSize());
245:                                 currentCount += gs.getGroupSize();
246:                                 this.addChild(group);
247:                         }
248:
249:                         TraceTestGroup group = new TraceTestGroup(currentCount + 1, stopNumber + 1);
250:                         this.addChild(group);
251:
252:                 }
253:
254:         }
255:
256:         public void unloadTests()
257:         {
258:                 removeChildern();
259:                 addChild(new NotYetReadyTreeNode());
260:         }
261:
262:         public void removeChildern()
263:         {
264:                 for (int i = 0; i < children.size(); i++)
265:                 {
266:
267:                         ITreeNode tmp = children.get(i);
268:                         removeChild(tmp);
269:
270:                         tmp = null;
271:                 }
272:                 children = new Vector<ITreeNode>();
273:                 System.gc();
274:         }
275:
276:         public static Double numberOfLevels(Long count, Long groupSize)
277:         {
278:                 if (count / groupSize > groupSize)
279:                 {
280:                         return new Double(1) + numberOfLevels(count / groupSize, groupSize);
281:                 } else
282:                 {
283:                         return new Double(1);
284:                 }
285:
286:         }
287:
288: }