Coverage Report - com.puppycrawl.tools.checkstyle.api.FilterSet
 
Classes in this File Line Coverage Branch Coverage Complexity
FilterSet
78%
15/19
83%
5/6
1.625
 
 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  613
 public class FilterSet
 31  
     implements Filter
 32  
 {
 33  
     /** filter set */
 34  613
     private final Set<Filter> mFilters = Sets.newHashSet();
 35  
 
 36  
     /**
 37  
      * Adds a Filter to the set.
 38  
      * @param aFilter the Filter to add.
 39  
      */
 40  
     public void addFilter(Filter aFilter)
 41  
     {
 42  28
         mFilters.add(aFilter);
 43  28
     }
 44  
 
 45  
     /**
 46  
      * Removes filter.
 47  
      * @param aFilter filter to remove.
 48  
      */
 49  
     public void removeFilter(Filter aFilter)
 50  
     {
 51  1
         mFilters.remove(aFilter);
 52  1
     }
 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  0
         return mFilters;
 61  
     }
 62  
 
 63  
     @Override
 64  
     public String toString()
 65  
     {
 66  0
         return mFilters.toString();
 67  
     }
 68  
 
 69  
     @Override
 70  
     public int hashCode()
 71  
     {
 72  0
         return mFilters.hashCode();
 73  
     }
 74  
 
 75  
     @Override
 76  
     public boolean equals(Object aObject)
 77  
     {
 78  4
         if (aObject instanceof FilterSet) {
 79  4
             final FilterSet other = (FilterSet) aObject;
 80  4
             return this.mFilters.equals(other.mFilters);
 81  
         }
 82  0
         return false;
 83  
     }
 84  
 
 85  
     /** {@inheritDoc} */
 86  
     public boolean accept(AuditEvent aEvent)
 87  
     {
 88  3430
         for (Filter filter : mFilters) {
 89  308
             if (!filter.accept(aEvent)) {
 90  41
                 return false;
 91  
             }
 92  
         }
 93  3389
         return true;
 94  
     }
 95  
 
 96  
     /** Clears the FilterSet. */
 97  
     public void clear()
 98  
     {
 99  584
         mFilters.clear();
 100  584
     }
 101  
 }