1 package spoon.support.query; 2 3 import spoon.reflect.declaration.CtElement; 4 import spoon.reflect.visitor.Filter; 5 6 12 public class CompositeFilter<T extends CtElement> implements Filter<T> { 13 14 17 public boolean matches(T element) { 18 switch (operator) { 19 case INTERSECTION: 20 for (Filter<T> f : filters) { 21 if (!f.matches(element)) 22 return false; 23 } 24 return true; 25 case UNION: 26 for (Filter<T> f : filters) { 27 if (f.matches(element)) 28 return true; 29 } 30 return false; 31 case SUBSTRACTION: 32 if (filters.length == 0) 33 return false; 34 if (!filters[0].matches(element)) 35 return false; 36 for (int i = 1; i < filters.length; i++) { 37 if (filters[i].matches(element)) 38 return false; 39 } 40 return true; 41 default: 42 return false; 43 } 44 } 45 46 Filter<T>[] filters; 47 48 FilteringOperator operator; 49 50 56 public CompositeFilter(FilteringOperator operator, Filter<T>... filters) { 57 this.filters = filters; 58 this.operator = operator; 59 } 60 61 @SuppressWarnings ("unchecked") 62 public Class <T> getType() { 63 return (Class <T>) CtElement.class; 64 } 65 66 } 67 | Popular Tags |