View Javadoc

1   package net.sourceforge.argval.collection;
2   
3   
4   import java.util.Iterator;
5   import java.util.List;
6   
7   
8   /**
9    * 
10   * @author T. Verhagen
11   */
12  public class FilterImpl implements Filter {
13      private List<String> rejectList = null;
14      private List<String> acceptList = null;
15      
16      
17      public FilterImpl(List<String> rejectList, List<String> acceptList) {
18          super();
19          this.rejectList = rejectList;
20          this.acceptList = acceptList;
21      }
22  
23  
24      public boolean accept(String value) {
25          List<String> list = rejectList;
26          boolean isAccepted = false;
27          if (list != null && list.size() > 0) {
28              for (Iterator<String> iter = list.iterator(); iter.hasNext();) {
29                  String element = (String)iter.next();
30                  if (value.startsWith(element)) {
31                      return false;
32                  }
33              }
34          }
35          list = acceptList;
36          isAccepted = true;
37          if (list != null && list.size() > 0) {
38              for (Iterator<String> iter = list.iterator(); iter.hasNext();) {
39                  String element = (String)iter.next();
40                  if (value.startsWith(element)) {
41                      return isAccepted;
42                  }
43              }
44          }
45          return true;
46      }
47      /*
48      public boolean accept(String value) {
49          return accept(rejectList, false, value) |
50              accept(acceptList, true, value);
51  //        return true;
52      }
53  
54  
55      private boolean accept(List list, boolean isAccepted, String value) {
56          if (list != null && list.size() > 0) {
57              for (Iterator iter = list.iterator(); iter.hasNext();) {
58                  String element = (String)iter.next();
59                  if (value.startsWith(element)) {
60                      return isAccepted;
61                  }
62              }
63          }
64          return ! isAccepted;
65      }
66       */
67  }