01: /*
02: * FindBugs - Find Bugs in Java programs
03: * Copyright (C) 2006, 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:
20: package edu.umd.cs.findbugs.filter;
21:
22: import edu.umd.cs.findbugs.annotations.CheckForNull;
23: import edu.umd.cs.findbugs.util.Util;
24:
25: /**
26: * @author pugh
27: */
28: public class MemberMatcher {
29:
30: protected final NameMatch name;
31:
32: @CheckForNull
33: protected final String signature;
34:
35: public MemberMatcher(String name) {
36: this .name = new NameMatch(name);
37: this .signature = null;
38: }
39:
40: public MemberMatcher(String name, String signature) {
41:
42: if (name == null) {
43: if (signature == null)
44: throw new FilterException(
45: this .getClass().getName()
46: + " must have eiter name or signature attributes");
47: else
48: name = "~.*"; // any name
49: }
50:
51: this .name = new NameMatch(name);
52: this .signature = signature;
53:
54: }
55:
56: @Override
57: public String toString() {
58: StringBuffer buf = new StringBuffer();
59: if (!name.isUniversal()) {
60: buf.append("name=\"");
61: buf.append(name.getSpec());
62: buf.append("\"");
63: }
64: if (signature != null) {
65: if (buf.length() > 0)
66: buf.append(" ");
67: buf.append("signature=\"");
68: buf.append(signature);
69: buf.append("\"");
70: }
71: return buf.toString();
72: }
73:
74: @Override
75: public int hashCode() {
76: return name.hashCode() + Util.nullSafeHashcode(signature);
77: }
78:
79: @Override
80: public boolean equals(Object o) {
81: if (o == null || this .getClass() != o.getClass())
82: return false;
83:
84: MemberMatcher other = (MemberMatcher) o;
85: return name.equals(other.name)
86: && Util.nullSafeEquals(signature, other.signature);
87: }
88:
89: }
|