001/////////////////////////////////////////////////////////////////////////////////////////////// 002// checkstyle: Checks Java source code and other text files for adherence to a set of rules. 003// Copyright (C) 2001-2026 the original author or authors. 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/////////////////////////////////////////////////////////////////////////////////////////////// 019 020package com.puppycrawl.tools.checkstyle.api; 021 022import java.util.Collections; 023import java.util.HashSet; 024import java.util.Set; 025 026/** 027 * A filter set applies filters to AuditEvents. 028 * If a filter in the set rejects an AuditEvent, then the 029 * AuditEvent is rejected. Otherwise, the AuditEvent is accepted. 030 */ 031public class FilterSet 032 implements Filter { 033 034 /** Filter set. */ 035 private final Set<Filter> filters = new HashSet<>(); 036 037 /** 038 * Creates a new {@code FilterSet} instance. 039 */ 040 public FilterSet() { 041 // no code by default 042 } 043 044 /** 045 * Adds a Filter to the set. 046 * 047 * @param filter the Filter to add. 048 */ 049 public void addFilter(Filter filter) { 050 filters.add(filter); 051 } 052 053 /** 054 * Removes filter. 055 * 056 * @param filter filter to remove. 057 */ 058 public void removeFilter(Filter filter) { 059 filters.remove(filter); 060 } 061 062 /** 063 * Returns the Filters of the filter set. 064 * 065 * @return the Filters of the filter set. 066 */ 067 public Set<Filter> getFilters() { 068 return Collections.unmodifiableSet(filters); 069 } 070 071 @Override 072 public String toString() { 073 return filters.toString(); 074 } 075 076 @Override 077 public boolean accept(AuditEvent event) { 078 boolean result = true; 079 for (Filter filter : filters) { 080 if (!filter.accept(event)) { 081 result = false; 082 break; 083 } 084 } 085 return result; 086 } 087 088 /** Clears the FilterSet. */ 089 public void clear() { 090 filters.clear(); 091 } 092 093}