--- /dev/null
+package net.jaekl.cfb.analyze;
+
+import java.util.HashSet;
+
+import net.jaekl.cfb.xml.BugInstance;
+
+// Compute and store the delta (difference) between two analyses
+
+public class Delta {
+ HashSet<BugInstance> m_fixed; // bugs that have been fixed
+ HashSet<BugInstance> m_common; // bugs that are present in both versions
+ HashSet<BugInstance> m_new; // bugs introduced in the new version
+
+ public Delta(Analysis before, Analysis after)
+ {
+ m_fixed = new HashSet<BugInstance>();
+ m_common = new HashSet<BugInstance>();
+ m_new = new HashSet<BugInstance>();
+
+ computeDelta(before, after);
+ }
+
+ public BugInstance[] getFixed() { return m_fixed.toArray(new BugInstance[m_fixed.size()]); }
+ public int getNumFixed() { return m_fixed.size(); }
+
+ public BugInstance[] getCommon() { return m_common.toArray(new BugInstance[m_common.size()]); }
+ public int getNumCommon() { return m_common.size(); }
+
+ public BugInstance[] getNew() { return m_new.toArray(new BugInstance[m_new.size()]); }
+ public int getNumNew() { return m_new.size(); }
+
+ void computeDelta(Analysis before, Analysis after)
+ {
+ m_fixed.clear();
+ m_common.clear();
+ m_new.clear();
+
+ HashSet<BugInstance> beforeBugs = new HashSet<BugInstance>();
+
+ beforeBugs.addAll(before.getBugCollection().getBugs());
+
+ for (BugInstance bug : after.getBugCollection().getBugs()) {
+ if (beforeBugs.contains(bug)) {
+ m_common.add(bug);
+ }
+ else {
+ m_new.add(bug);
+ }
+ }
+
+ for (BugInstance bug : before.getBugCollection().getBugs()) {
+ if (! m_common.contains(bug)) {
+ m_fixed.add(bug);
+ }
+ }
+ }
+}