1 //////////////////////////////////////////////////////////////////////////////// 2 // checkstyle: Checks Java source code for adherence to a set of rules. 3 // Copyright (C) 2001-2014 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 com.google.common.collect.Sets; 22 import java.util.Set; 23 24 /** 25 * A filter set applies filters to AuditEvents. 26 * If a filter in the set rejects an AuditEvent, then the 27 * AuditEvent is rejected. Otherwise, the AuditEvent is accepted. 28 * @author Rick Giles 29 */ 30 public class FilterSet 31 implements Filter 32 { 33 /** filter set */ 34 private final Set<Filter> filters = Sets.newHashSet(); 35 36 /** 37 * Adds a Filter to the set. 38 * @param filter the Filter to add. 39 */ 40 public void addFilter(Filter filter) 41 { 42 filters.add(filter); 43 } 44 45 /** 46 * Removes filter. 47 * @param filter filter to remove. 48 */ 49 public void removeFilter(Filter filter) 50 { 51 filters.remove(filter); 52 } 53 54 /** 55 * Returns the Filters of the filter set. 56 * @return the Filters of the filter set. 57 */ 58 protected Set<Filter> getFilters() 59 { 60 return filters; 61 } 62 63 @Override 64 public String toString() 65 { 66 return filters.toString(); 67 } 68 69 @Override 70 public int hashCode() 71 { 72 return filters.hashCode(); 73 } 74 75 @Override 76 public boolean equals(Object object) 77 { 78 if (object instanceof FilterSet) { 79 final FilterSet other = (FilterSet) object; 80 return this.filters.equals(other.filters); 81 } 82 return false; 83 } 84 85 /** {@inheritDoc} */ 86 @Override 87 public boolean accept(AuditEvent event) 88 { 89 for (Filter filter : filters) { 90 if (!filter.accept(event)) { 91 return false; 92 } 93 } 94 return true; 95 } 96 97 /** Clears the FilterSet. */ 98 public void clear() 99 { 100 filters.clear(); 101 } 102 }