Coverage Report - net.sf.json.filters.CompositePropertyFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
CompositePropertyFilter
0%
0/23
0%
0/14
2.6
 
 1  
 /*
 2  
  * Copyright 2002-2009 the original author or authors.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 
 17  
 package net.sf.json.filters;
 18  
 
 19  
 import java.util.ArrayList;
 20  
 import java.util.Iterator;
 21  
 import java.util.List;
 22  
 
 23  
 import net.sf.json.util.PropertyFilter;
 24  
 
 25  
 /**
 26  
  * @author Andres Almiray <aalmiray@users.sourceforge.net>
 27  
  */
 28  
 public class CompositePropertyFilter implements PropertyFilter {
 29  0
    private List filters = new ArrayList();
 30  
 
 31  
    public CompositePropertyFilter() {
 32  0
       this( null );
 33  0
    }
 34  
 
 35  0
    public CompositePropertyFilter( List filters ) {
 36  0
       if( filters != null ){
 37  0
          for( Iterator i = filters.iterator(); i.hasNext(); ){
 38  0
             Object filter = i.next();
 39  0
             if( filter instanceof PropertyFilter ){
 40  0
                this.filters.add( filter );
 41  
             }
 42  0
          }
 43  
       }
 44  0
    }
 45  
 
 46  
    public void addPropertyFilter( PropertyFilter filter ) {
 47  0
       if( filter != null ){
 48  0
          filters.add( filter );
 49  
       }
 50  0
    }
 51  
 
 52  
    public boolean apply( Object source, String name, Object value ) {
 53  0
       for( Iterator i = filters.iterator(); i.hasNext(); ){
 54  0
          PropertyFilter filter = (PropertyFilter) i.next();
 55  0
          if( filter.apply( source, name, value ) ){
 56  0
             return true;
 57  
          }
 58  0
       }
 59  0
       return false;
 60  
    }
 61  
 
 62  
    public void removePropertyFilter( PropertyFilter filter ) {
 63  0
       if( filter != null ){
 64  0
          filters.remove( filter );
 65  
       }
 66  0
    }
 67  
 }