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 class PredicateTransformer implements Transformer, Serializable { 33 34 35 static final long serialVersionUID = 5278818408044349346L; 36 37 38 private final Predicate iPredicate; 39 40 47 public static Transformer getInstance(Predicate predicate) { 48 if (predicate == null) { 49 throw new IllegalArgumentException ("Predicate must not be null"); 50 } 51 return new PredicateTransformer(predicate); 52 } 53 54 60 public PredicateTransformer(Predicate predicate) { 61 super(); 62 iPredicate = predicate; 63 } 64 65 71 public Object transform(Object input) { 72 return (iPredicate.evaluate(input) ? Boolean.TRUE : Boolean.FALSE); 73 } 74 75 81 public Predicate getPredicate() { 82 return iPredicate; 83 } 84 85 } 86 | Popular Tags |