01: ////////////////////////////////////////////////////////////////////////////////
02: // checkstyle: Checks Java source code for adherence to a set of rules.
03: // Copyright (C) 2001-2007 Oliver Burn
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 com.puppycrawl.tools.checkstyle.api;
20:
21: import java.util.HashSet;
22: import java.util.Iterator;
23: import java.util.Set;
24:
25: /**
26: * A filter set applies filters to AuditEvents.
27: * If a filter in the set rejects an AuditEvent, then the
28: * AuditEvent is rejected. Otherwise, the AuditEvent is accepted.
29: * @author Rick Giles
30: */
31: public class FilterSet implements Filter {
32: /** filter set */
33: private final Set mFilters = new HashSet();
34:
35: /**
36: * Adds a Filter to the set.
37: * @param aFilter the Filter to add.
38: */
39: public void addFilter(Filter aFilter) {
40: mFilters.add(aFilter);
41: }
42:
43: /**
44: * Removes filter.
45: * @param aFilter filter to remove.
46: */
47: public void removeFilter(Filter aFilter) {
48: mFilters.remove(aFilter);
49: }
50:
51: /**
52: * Returns the Filters of the filter set.
53: * @return the Filters of the filter set.
54: */
55: protected Set getFilters() {
56: return mFilters;
57: }
58:
59: /** {@inheritDoc} */
60: public String toString() {
61: return mFilters.toString();
62: }
63:
64: /** {@inheritDoc} */
65: public int hashCode() {
66: return mFilters.hashCode();
67: }
68:
69: /** {@inheritDoc} */
70: public boolean equals(Object aObject) {
71: if (aObject instanceof FilterSet) {
72: final FilterSet other = (FilterSet) aObject;
73: return this .mFilters.equals(other.mFilters);
74: }
75: return false;
76: }
77:
78: /** {@inheritDoc} */
79: public boolean accept(AuditEvent aEvent) {
80: final Iterator it = mFilters.iterator();
81: while (it.hasNext()) {
82: final Filter filter = (Filter) it.next();
83: if (!filter.accept(aEvent)) {
84: return false;
85: }
86: }
87: return true;
88: }
89:
90: /** Clears the FilterSet. */
91: public void clear() {
92: mFilters.clear();
93: }
94: }
|