1 package jp.sourceforge.stigmata;
7 import java.util.ArrayList;
8 import java.util.Iterator;
13 * Set of {@link ComparisonPairFilter <Ccode>ComparisonPairFilter</code>}.
15 * @author Haruaki TAMADA
17 public class ComparisonPairFilterSet implements Iterable<ComparisonPairFilter>{
18 private List<ComparisonPairFilter> filters = new ArrayList<ComparisonPairFilter>();
20 private boolean matchall = true;
22 public boolean isFiltered(ComparisonPair pair){
24 if(isMatchAll()){ // all of criteria are matched?
26 for(ComparisonPairFilter filter: filters){
27 if(!filter.isFiltered(pair)){
33 else{ // any of criteria are matched
35 for(ComparisonPairFilter filter: filters){
36 if(filter.isFiltered(pair)){
46 * returns a flag that all filters must be matched.
48 public boolean isMatchAll(){
53 * returns a flag that any filters must be matched.
55 public boolean isMatchAny(){
60 * filtering if all criteria is matched.
62 public void setMatchAll(){
67 * filtering if any criterion is matched.
69 public void setMatchAny(){
73 public void setName(String name){
77 public String getName(){
81 public boolean addFilter(ComparisonPairFilter o){
82 return filters.add(o);
85 public void removeAllFilters(){
89 public ComparisonPairFilter getFilter(int index){
90 return filters.get(index);
94 public Iterator<ComparisonPairFilter> iterator(){
95 return filters.iterator();
98 public ComparisonPairFilter removeFilter(int index){
99 return filters.remove(index);
102 public int getFilterCount(){
103 return filters.size();
107 public String toString(){
108 StringBuilder sb = new StringBuilder("filterset{ ");
109 sb.append("name=").append(getName()).append(", ");
110 sb.append(isMatchAll()? "match_all": "match_any");
111 sb.append(", ").append(filters).append("}");
113 return new String(sb);