THashMap<String, THashMap<String, BranchPoint[]>> combined =\r
new THashMap<String, THashMap<String, BranchPoint[]>>();\r
\r
- public void addCoverage(Module module) {\r
+ public void addCoverage(Module module, boolean persistOverBranchpointReset) {\r
THashMap<String, BranchPoint[]> branchPointMap = module.getBranchPoints();\r
if(branchPointMap == null)\r
return;\r
@Override\r
public boolean execute(String name, BranchPoint[] branchPoints) {\r
BranchPoint[] oldBranchPoints = oldBranchPointMap_.get(name);\r
- if(oldBranchPoints == null)\r
- oldBranchPointMap_.put(name, branchPoints);\r
- else\r
+ if(oldBranchPoints == null) {\r
+ if (persistOverBranchpointReset) {\r
+ // Clone the branchPoints array so that if will last over a reset\r
+ BranchPoint[] clonedBranchPoints = cloneBranchPoints(branchPoints);\r
+ oldBranchPointMap_.put(name, clonedBranchPoints);\r
+ } else {\r
+ // No need to copy so resetting branchpoints will reset this as well\r
+ oldBranchPointMap_.put(name, branchPoints);\r
+ }\r
+ } else {\r
combineCounters(oldBranchPoints, branchPoints);\r
+ }\r
return true;\r
}\r
});\r
}\r
\r
+ private static BranchPoint[] cloneBranchPoints(BranchPoint[] oldBranchPoints) {\r
+ BranchPoint[] newBranchPoints = new BranchPoint[oldBranchPoints.length];\r
+ for (int i = 0; i < oldBranchPoints.length; i++) {\r
+ BranchPoint bp = oldBranchPoints[i];\r
+ BranchPoint[] children = cloneBranchPoints(bp.getChildren());\r
+ newBranchPoints[i] = new BranchPoint(bp.getLocation(), bp.getCodeSize(), children);\r
+ }\r
+ return newBranchPoints;\r
+ }\r
+ \r
private static void combineCounters(BranchPoint[] oldBranchPoints, BranchPoint[] branchPoints) {\r
if(oldBranchPoints.length != branchPoints.length)\r
throw new IllegalArgumentException("Incompatible branch points.");\r
for(int i=0;i<branchPoints.length;++i) {\r
BranchPoint oldBP = oldBranchPoints[i];\r
BranchPoint newBP = branchPoints[i];\r
- if(oldBP.location != newBP.location)\r
+ if(oldBP.getLocation() != newBP.getLocation())\r
throw new IllegalArgumentException("Incompatible branch points.");\r
- oldBP.visitCounter += newBP.visitCounter;\r
- combineCounters(oldBP.children, newBP.children);\r
+ oldBP.incrementVisitCounter(newBP.getVisitCounter());\r
+ combineCounters(oldBP.getChildren(), newBP.getChildren());\r
}\r
}\r
\r