1 16 package org.apache.commons.collections.functors; 17 18 import java.io.Serializable ; 19 20 import org.apache.commons.collections.Predicate; 21 import org.apache.commons.collections.Transformer; 22 23 32 public final class TransformedPredicate implements Predicate, PredicateDecorator, Serializable { 33 34 35 static final long serialVersionUID = -5596090919668315834L; 36 37 38 private final Transformer iTransformer; 39 40 private final Predicate iPredicate; 41 42 50 public static Predicate getInstance(Transformer transformer, Predicate predicate) { 51 if (transformer == null) { 52 throw new IllegalArgumentException ("The transformer to call must not be null"); 53 } 54 if (predicate == null) { 55 throw new IllegalArgumentException ("The predicate to call must not be null"); 56 } 57 return new TransformedPredicate(transformer, predicate); 58 } 59 60 67 public TransformedPredicate(Transformer transformer, Predicate predicate) { 68 iTransformer = transformer; 69 iPredicate = predicate; 70 } 71 72 79 public boolean evaluate(Object object) { 80 Object result = iTransformer.transform(object); 81 return iPredicate.evaluate(result); 82 } 83 84 90 public Predicate[] getPredicates() { 91 return new Predicate[] {iPredicate}; 92 } 93 94 99 public Transformer getTransformer() { 100 return iTransformer; 101 } 102 103 } 104 | Popular Tags |