1 16 package org.apache.commons.collections.functors; 17 18 import java.io.Serializable ; 19 20 import org.apache.commons.collections.Predicate; 21 22 30 public final class OrPredicate implements Predicate, PredicateDecorator, Serializable { 31 32 33 static final long serialVersionUID = -8791518325735182855L; 34 35 36 private final Predicate iPredicate1; 37 38 private final Predicate iPredicate2; 39 40 48 public static Predicate getInstance(Predicate predicate1, Predicate predicate2) { 49 if (predicate1 == null || predicate2 == null) { 50 throw new IllegalArgumentException ("Predicate must not be null"); 51 } 52 return new OrPredicate(predicate1, predicate2); 53 } 54 55 62 public OrPredicate(Predicate predicate1, Predicate predicate2) { 63 super(); 64 iPredicate1 = predicate1; 65 iPredicate2 = predicate2; 66 } 67 68 74 public boolean evaluate(Object object) { 75 return (iPredicate1.evaluate(object) || iPredicate2.evaluate(object)); 76 } 77 78 84 public Predicate[] getPredicates() { 85 return new Predicate[] {iPredicate1, iPredicate2}; 86 } 87 88 } 89 | Popular Tags |