01: /*
02: * FindBugs - Find bugs in Java programs
03: * Copyright (C) 2005, University of Maryland
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
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.filter;
20:
21: import java.io.IOException;
22:
23: import edu.umd.cs.findbugs.BugInstance;
24: import edu.umd.cs.findbugs.xml.XMLAttributeList;
25: import edu.umd.cs.findbugs.xml.XMLOutput;
26:
27: /**
28: * Matcher to select BugInstances with a particular last version.
29: */
30: public class LastVersionMatcher extends VersionMatcher implements
31: Matcher {
32:
33: public final static LastVersionMatcher DEAD_BUG_MATCHER = new LastVersionMatcher(
34: -1, RelationalOp.NEQ);
35:
36: public LastVersionMatcher(String versionAsString,
37: String relOpAsString) {
38: this (Long.parseLong(versionAsString), RelationalOp
39: .byName(relOpAsString));
40: }
41:
42: public LastVersionMatcher(String versionAsString, RelationalOp relOp) {
43: this (Long.parseLong(versionAsString), relOp);
44: }
45:
46: public LastVersionMatcher(long version, RelationalOp relOp) {
47: super (version, relOp);
48: }
49:
50: public boolean match(BugInstance bugInstance) {
51: return relOp.check(bugInstance.getLastVersion(), version);
52: }
53:
54: public void writeXML(XMLOutput xmlOutput, boolean disabled)
55: throws IOException {
56: XMLAttributeList attributes = new XMLAttributeList()
57: .addAttribute("value", Long.toString(version))
58: .addAttribute("relOp", relOp.getName());
59: if (disabled)
60: attributes.addAttribute("disabled", "true");
61: xmlOutput.openCloseTag("LastVersion", attributes);
62: }
63:
64: @Override
65: public String toString() {
66: if (version == -1 && relOp == RelationalOp.EQ)
67: return "ActiveBugs()";
68: else if (version == -1 && relOp == RelationalOp.NEQ)
69: return "DeadBugs()";
70: return "LastVersion(version " + relOp + version + ")";
71: }
72: }
|