1 16 package org.apache.commons.collections.functors; 17 18 import java.io.Serializable ; 19 import java.util.Collection ; 20 21 import org.apache.commons.collections.Predicate; 22 23 31 public final class OnePredicate implements Predicate, PredicateDecorator, Serializable { 32 33 34 static final long serialVersionUID = -8125389089924745785L; 35 36 37 private final Predicate[] iPredicates; 38 39 48 public static Predicate getInstance(Predicate[] predicates) { 49 FunctorUtils.validateMin2(predicates); 50 predicates = FunctorUtils.copy(predicates); 51 return new OnePredicate(predicates); 52 } 53 54 63 public static Predicate getInstance(Collection predicates) { 64 Predicate[] preds = FunctorUtils.validate(predicates); 65 return new OnePredicate(preds); 66 } 67 68 74 public OnePredicate(Predicate[] predicates) { 75 super(); 76 iPredicates = predicates; 77 } 78 79 86 public boolean evaluate(Object object) { 87 boolean match = false; 88 for (int i = 0; i < iPredicates.length; i++) { 89 if (iPredicates[i].evaluate(object)) { 90 if (match) { 91 return false; 92 } 93 match = true; 94 } 95 } 96 return match; 97 } 98 99 105 public Predicate[] getPredicates() { 106 return iPredicates; 107 } 108 109 } 110 | Popular Tags |