1 package net.sourceforge.argval.collection; 2 3 4 import java.util.Iterator; 5 import java.util.Set; 6 import java.util.TreeSet; 7 8 9 public class CollectionFilter { 10 private Filter filter; 11 12 13 public CollectionFilter() { 14 super(); 15 } 16 public CollectionFilter(Filter filter) { 17 this(); 18 this.filter = filter; 19 } 20 21 22 public Set<String> filter(Set<String> strSet) { 23 if (filter == null) { 24 return strSet; 25 } 26 27 Set<String> filteredSet = new TreeSet<String>(); 28 for (Iterator<String> iter = strSet.iterator(); iter.hasNext(); ) { 29 String element = (String)iter.next(); 30 if (filter.accept(element)) { 31 filteredSet.add(element); 32 } 33 } 34 return filteredSet; 35 } 36 37 }