KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > api > FilterSet


1 ////////////////////////////////////////////////////////////////////////////////
2
// checkstyle: Checks Java source code for adherence to a set of rules.
3
// Copyright (C) 2001-2005 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 JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.Set JavaDoc;
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 final Set JavaDoc mFilters = new HashSet JavaDoc();
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 JavaDoc getFilters()
60     {
61         return mFilters;
62     }
63
64     /** {@inheritDoc} */
65     public String JavaDoc toString()
66     {
67         return mFilters.toString();
68     }
69
70     /** {@inheritDoc} */
71     public int hashCode()
72     {
73         return mFilters.hashCode();
74     }
75
76     /** {@inheritDoc} */
77     public boolean equals(Object JavaDoc aObject)
78     {
79         if (aObject instanceof FilterSet) {
80             final FilterSet other = (FilterSet) aObject;
81             return this.mFilters.equals(other.mFilters);
82         }
83         return false;
84     }
85
86     /** {@inheritDoc} */
87     public boolean accept(AuditEvent aEvent)
88     {
89         final Iterator JavaDoc it = mFilters.iterator();
90         while (it.hasNext()) {
91             final Filter filter = (Filter) it.next();
92             if (!filter.accept(aEvent)) {
93                 return false;
94             }
95         }
96         return true;
97     }
98
99     /** Clears the FilterSet. */
100     public void clear()
101     {
102         mFilters.clear();
103     }
104 }
105
Popular Tags