Coverage Report - com.puppycrawl.tools.checkstyle.api.BeforeExecutionFileFilterSet
 
Classes in this File Line Coverage Branch Coverage Complexity
BeforeExecutionFileFilterSet
100%
17/17
100%
4/4
1.333
 
 1  
 ////////////////////////////////////////////////////////////////////////////////
 2  
 // checkstyle: Checks Java source code for adherence to a set of rules.
 3  
 // Copyright (C) 2001-2018 the original author or authors.
 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  
 
 20  
 package com.puppycrawl.tools.checkstyle.api;
 21  
 
 22  
 import java.util.Collections;
 23  
 import java.util.HashSet;
 24  
 import java.util.Set;
 25  
 
 26  
 /**
 27  
  * A before execution file filter set applies filters to events.
 28  
  * If a before execution file filter in the set rejects an event, then the
 29  
  * event is rejected. Otherwise, the event is accepted.
 30  
  * @author Richard Veach
 31  
  */
 32  2065
 public final class BeforeExecutionFileFilterSet
 33  
     implements BeforeExecutionFileFilter {
 34  
 
 35  
     /** Filter set. */
 36  2065
     private final Set<BeforeExecutionFileFilter> beforeExecutionFileFilters = new HashSet<>();
 37  
 
 38  
     /**
 39  
      * Adds a Filter to the set.
 40  
      * @param filter the Filter to add.
 41  
      */
 42  
     public void addBeforeExecutionFileFilter(BeforeExecutionFileFilter filter) {
 43  13
         beforeExecutionFileFilters.add(filter);
 44  13
     }
 45  
 
 46  
     /**
 47  
      * Removes filter.
 48  
      * @param filter filter to remove.
 49  
      */
 50  
     public void removeBeforeExecutionFileFilter(BeforeExecutionFileFilter filter) {
 51  1
         beforeExecutionFileFilters.remove(filter);
 52  1
     }
 53  
 
 54  
     /**
 55  
      * Returns the Filters of the filter set.
 56  
      * @return the Filters of the filter set.
 57  
      */
 58  
     public Set<BeforeExecutionFileFilter> getBeforeExecutionFileFilters() {
 59  3
         return Collections.unmodifiableSet(beforeExecutionFileFilters);
 60  
     }
 61  
 
 62  
     @Override
 63  
     public String toString() {
 64  1
         return beforeExecutionFileFilters.toString();
 65  
     }
 66  
 
 67  
     @Override
 68  
     public boolean accept(String uri) {
 69  1618
         boolean result = true;
 70  1618
         for (BeforeExecutionFileFilter filter : beforeExecutionFileFilters) {
 71  7
             if (!filter.accept(uri)) {
 72  2
                 result = false;
 73  2
                 break;
 74  
             }
 75  5
         }
 76  1618
         return result;
 77  
     }
 78  
 
 79  
     /** Clears the BeforeExecutionFileFilterSet. */
 80  
     public void clear() {
 81  1965
         beforeExecutionFileFilters.clear();
 82  1965
     }
 83  
 
 84  
 }