KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > umd > cs > findbugs > NewResults


1 /*
2  * FindBugs - Find bugs in Java programs
3  * Copyright (C) 2004, University of Maryland
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package edu.umd.cs.findbugs;
20
21 import java.io.IOException JavaDoc;
22 import java.util.Iterator JavaDoc;
23
24 import org.dom4j.DocumentException;
25
26 public class NewResults {
27     private SortedBugCollection origCollection;
28     private SortedBugCollection newCollection;
29     private Project project;
30
31     public NewResults(String JavaDoc origFilename, String JavaDoc newFilename)
32             throws IOException JavaDoc, DocumentException {
33         this(new SortedBugCollection(), new SortedBugCollection(), new Project());
34         origCollection.readXML(origFilename, new Project());
35         newCollection.readXML(newFilename, project);
36     }
37
38     public NewResults(SortedBugCollection origCollection, SortedBugCollection newCollection,
39         Project project) {
40         this.origCollection = origCollection;
41         this.newCollection = newCollection;
42         this.project = project;
43     }
44
45     public SortedBugCollection execute() {
46         SortedBugCollection result = new SortedBugCollection();
47
48         for (Iterator JavaDoc<BugInstance> i= newCollection.iterator(); i.hasNext(); ) {
49             BugInstance bugInstance = i.next();
50
51             if (!origCollection.contains(bugInstance)) {
52                 result.add(bugInstance);
53             }
54         }
55
56         return result;
57     }
58
59     public static void main(String JavaDoc[] argv) throws Exception JavaDoc {
60         if (argv.length != 3) {
61             System.err.println("Usage: " + NewResults.class.getName() +
62                 " <orig results> <new results> <output file>");
63             System.exit(1);
64         }
65
66         String JavaDoc origFilename = argv[0];
67         String JavaDoc newFilename = argv[1];
68         String JavaDoc outputFilename = argv[2];
69
70         NewResults op = new NewResults(origFilename, newFilename);
71
72         SortedBugCollection result = op.execute();
73
74         result.writeXML(outputFilename, op.project);
75     }
76 }
77
78 // vim:ts=4
79
Popular Tags