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.filters; 020 021import com.puppycrawl.tools.checkstyle.api.AuditEvent; 022import com.puppycrawl.tools.checkstyle.api.AutomaticBean; 023import com.puppycrawl.tools.checkstyle.api.CheckstyleException; 024import com.puppycrawl.tools.checkstyle.api.Filter; 025import com.puppycrawl.tools.checkstyle.api.FilterSet; 026 027/** 028 * <p> 029 * This filter accepts AuditEvents according to file, check, line, and 030 * column, as specified in a suppression file. 031 * </p> 032 * @author Rick Giles 033 */ 034public class SuppressionFilter 035 extends AutomaticBean 036 implements Filter 037{ 038 /** set of individual suppresses */ 039 private FilterSet mFilters = new FilterSet(); 040 041 /** 042 * Loads the suppressions for a file. 043 * @param aFileName name of the suppressions file. 044 * @throws CheckstyleException if there is an error. 045 */ 046 public void setFile(String aFileName) 047 throws CheckstyleException 048 { 049 mFilters = SuppressionsLoader.loadSuppressions(aFileName); 050 } 051 052 /** {@inheritDoc} */ 053 public boolean accept(AuditEvent aEvent) 054 { 055 return mFilters.accept(aEvent); 056 } 057 058 @Override 059 public String toString() 060 { 061 return mFilters.toString(); 062 } 063 064 @Override 065 public int hashCode() 066 { 067 return mFilters.hashCode(); 068 } 069 070 @Override 071 public boolean equals(Object aObject) 072 { 073 if (aObject instanceof SuppressionFilter) { 074 final SuppressionFilter other = (SuppressionFilter) aObject; 075 return this.mFilters.equals(other.mFilters); 076 } 077 return false; 078 } 079}