View Javadoc

1   package net.sourceforge.argval.collection;
2   
3   
4   import java.util.HashSet;
5   import java.util.Iterator;
6   import java.util.LinkedList;
7   import java.util.List;
8   import java.util.Set;
9   
10  import net.sourceforge.argval.ArgumentValidation;
11  import net.sourceforge.argval.impl.ArgumentValidationImpl;
12  
13  
14  public class FilterGroup implements Filter {
15      private List<Filter> filterList = new LinkedList<Filter>();
16      
17  
18      public boolean accept(String value) {
19          return false;
20      }
21  
22      
23      public void addFilter(Filter filter) {
24          ArgumentValidation argVal = new ArgumentValidationImpl();
25          argVal.isValidWhenNotInSet("filter", filter.toString(), createFilterSet());
26          if (argVal.containsIllegalArgument()) throw argVal.createIllegalArgumentException();
27          
28          filterList.add(filter);
29      }
30  
31  
32      private Set<String> createFilterSet() {
33          Set<String> filterSet = new HashSet<String>(filterList.size());
34          for (Iterator<Filter> iter = filterList.iterator(); iter.hasNext();) {
35              Filter filter = (Filter)iter.next();
36              filterSet.add(filter.toString());
37          }
38          return filterSet;
39      }
40      
41  }