001//////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code for adherence to a set of rules. 003// Copyright (C) 2001-2014 Oliver Burn 004// 005// This library is free software; you can redistribute it and/or 006// modify it under the terms of the GNU Lesser General Public 007// License as published by the Free Software Foundation; either 008// version 2.1 of the License, or (at your option) any later version. 009// 010// This library is distributed in the hope that it will be useful, 011// but WITHOUT ANY WARRANTY; without even the implied warranty of 012// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013// Lesser General Public License for more details. 014// 015// You should have received a copy of the GNU Lesser General Public 016// License along with this library; if not, write to the Free Software 017// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018//////////////////////////////////////////////////////////////////////////////// 019package com.puppycrawl.tools.checkstyle.api; 020 021import com.google.common.collect.Sets; 022import java.util.Set; 023 024/** 025 * A filter set applies filters to AuditEvents. 026 * If a filter in the set rejects an AuditEvent, then the 027 * AuditEvent is rejected. Otherwise, the AuditEvent is accepted. 028 * @author Rick Giles 029 */ 030public class FilterSet 031 implements Filter 032{ 033 /** filter set */ 034 private final Set<Filter> mFilters = Sets.newHashSet(); 035 036 /** 037 * Adds a Filter to the set. 038 * @param aFilter the Filter to add. 039 */ 040 public void addFilter(Filter aFilter) 041 { 042 mFilters.add(aFilter); 043 } 044 045 /** 046 * Removes filter. 047 * @param aFilter filter to remove. 048 */ 049 public void removeFilter(Filter aFilter) 050 { 051 mFilters.remove(aFilter); 052 } 053 054 /** 055 * Returns the Filters of the filter set. 056 * @return the Filters of the filter set. 057 */ 058 protected Set<Filter> getFilters() 059 { 060 return mFilters; 061 } 062 063 @Override 064 public String toString() 065 { 066 return mFilters.toString(); 067 } 068 069 @Override 070 public int hashCode() 071 { 072 return mFilters.hashCode(); 073 } 074 075 @Override 076 public boolean equals(Object aObject) 077 { 078 if (aObject instanceof FilterSet) { 079 final FilterSet other = (FilterSet) aObject; 080 return this.mFilters.equals(other.mFilters); 081 } 082 return false; 083 } 084 085 /** {@inheritDoc} */ 086 public boolean accept(AuditEvent aEvent) 087 { 088 for (Filter filter : mFilters) { 089 if (!filter.accept(aEvent)) { 090 return false; 091 } 092 } 093 return true; 094 } 095 096 /** Clears the FilterSet. */ 097 public void clear() 098 { 099 mFilters.clear(); 100 } 101}