1 package net.sourceforge.argval.collection;
2
3
4 import java.util.Iterator;
5 import java.util.List;
6
7
8
9
10
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 }