Source code: com/puppycrawl/tools/checkstyle/api/FilterSet.java
1 ////////////////////////////////////////////////////////////////////////////////
2 // checkstyle: Checks Java source code for adherence to a set of rules.
3 // Copyright (C) 2001-2003 Oliver Burn
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 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
32 implements Filter
33 {
34 /** filter set */
35 private Set mFilters = new HashSet();
36
37 /**
38 * Adds a Filter to the set.
39 * @param aFilter the Filter to add.
40 */
41 public void addFilter(Filter aFilter)
42 {
43 mFilters.add(aFilter);
44 }
45
46 /**
47 * Removes filter.
48 * @param aFilter filter to remove.
49 */
50 public void removeFilter(Filter aFilter)
51 {
52 mFilters.remove(aFilter);
53 }
54
55 /**
56 * Returns the Filters of the filter set.
57 * @return the Filters of the filter set.
58 */
59 protected Set getFilters()
60 {
61 return mFilters;
62 }
63
64 /** @see java.lang.Object#toString() */
65 public String toString()
66 {
67 return mFilters.toString();
68 }
69
70 /** @see java.lang.Object#hashCode() */
71 public int hashCode()
72 {
73 return mFilters.hashCode();
74 }
75
76 /** @see java.lang.Object#equals(java.lang.Object) */
77 public boolean equals (Object aObject)
78 {
79 if (aObject instanceof FilterSet) {
80 final FilterSet other = (FilterSet) aObject;
81 return this.mFilters.equals(other.mFilters);
82 }
83 else {
84 return false;
85 }
86 }
87
88 /** @see com.puppycrawl.tools.checkstyle.api.Filter */
89 public boolean accept(AuditEvent aEvent)
90 {
91 final Iterator it = mFilters.iterator();
92 while (it.hasNext()) {
93 final Filter filter = (Filter) it.next();
94 if (!filter.accept(aEvent)) {
95 return false;
96 }
97 }
98 return true;
99 }
100
101 /** Clears the FilterSet. */
102 public void clear()
103 {
104 mFilters.clear();
105 }
106 }