Add computation of deltas (differences between Analysis runs).
[cfb.git] / prod / net / jaekl / cfb / analyze / Delta.java
1 package net.jaekl.cfb.analyze;
2
3 import java.util.HashSet;
4
5 import net.jaekl.cfb.xml.BugInstance;
6
7 // Compute and store the delta (difference) between two analyses
8
9 public class Delta {
10         HashSet<BugInstance> m_fixed;           // bugs that have been fixed
11         HashSet<BugInstance> m_common;  // bugs that are present in both versions
12         HashSet<BugInstance> m_new;             // bugs introduced in the new version
13         
14         public Delta(Analysis before, Analysis after)
15         {
16                 m_fixed = new HashSet<BugInstance>();
17                 m_common = new HashSet<BugInstance>();
18                 m_new = new HashSet<BugInstance>();
19                 
20                 computeDelta(before, after);
21         }
22         
23         public BugInstance[] getFixed() { return m_fixed.toArray(new BugInstance[m_fixed.size()]); }
24         public int getNumFixed() { return m_fixed.size(); }
25         
26         public BugInstance[] getCommon() { return m_common.toArray(new BugInstance[m_common.size()]); }
27         public int getNumCommon() { return m_common.size(); }
28         
29         public BugInstance[] getNew() { return m_new.toArray(new BugInstance[m_new.size()]); }
30         public int getNumNew() { return m_new.size(); }
31         
32         void computeDelta(Analysis before, Analysis after)
33         {
34                 m_fixed.clear();
35                 m_common.clear();
36                 m_new.clear();
37                 
38                 HashSet<BugInstance> beforeBugs = new HashSet<BugInstance>();
39                 
40                 beforeBugs.addAll(before.getBugCollection().getBugs());
41                 
42                 for (BugInstance bug : after.getBugCollection().getBugs()) {
43                         if (beforeBugs.contains(bug)) {
44                                 m_common.add(bug);
45                         }
46                         else {
47                                 m_new.add(bug);
48                         }
49                 }
50                 
51                 for (BugInstance bug : before.getBugCollection().getBugs()) {
52                         if (! m_common.contains(bug)) {
53                                 m_fixed.add(bug);
54                         }
55                 }
56         }
57 }