1 16 package org.apache.commons.collections; 17 18 import java.util.Collection ; 19 20 import org.apache.commons.collections.functors.AllPredicate; 21 import org.apache.commons.collections.functors.AndPredicate; 22 import org.apache.commons.collections.functors.AnyPredicate; 23 import org.apache.commons.collections.functors.EqualPredicate; 24 import org.apache.commons.collections.functors.ExceptionPredicate; 25 import org.apache.commons.collections.functors.FalsePredicate; 26 import org.apache.commons.collections.functors.IdentityPredicate; 27 import org.apache.commons.collections.functors.InstanceofPredicate; 28 import org.apache.commons.collections.functors.InvokerTransformer; 29 import org.apache.commons.collections.functors.NonePredicate; 30 import org.apache.commons.collections.functors.NotNullPredicate; 31 import org.apache.commons.collections.functors.NotPredicate; 32 import org.apache.commons.collections.functors.NullIsExceptionPredicate; 33 import org.apache.commons.collections.functors.NullIsFalsePredicate; 34 import org.apache.commons.collections.functors.NullIsTruePredicate; 35 import org.apache.commons.collections.functors.NullPredicate; 36 import org.apache.commons.collections.functors.OnePredicate; 37 import org.apache.commons.collections.functors.OrPredicate; 38 import org.apache.commons.collections.functors.TransformedPredicate; 39 import org.apache.commons.collections.functors.TransformerPredicate; 40 import org.apache.commons.collections.functors.TruePredicate; 41 import org.apache.commons.collections.functors.UniquePredicate; 42 43 74 public class PredicateUtils { 75 76 79 public PredicateUtils() { 80 super(); 81 } 82 83 86 94 public static Predicate exceptionPredicate() { 95 return ExceptionPredicate.INSTANCE; 96 } 97 98 105 public static Predicate truePredicate() { 106 return TruePredicate.INSTANCE; 107 } 108 109 116 public static Predicate falsePredicate() { 117 return FalsePredicate.INSTANCE; 118 } 119 120 127 public static Predicate nullPredicate() { 128 return NullPredicate.INSTANCE; 129 } 130 131 138 public static Predicate notNullPredicate() { 139 return NotNullPredicate.INSTANCE; 140 } 141 142 151 public static Predicate equalPredicate(Object value) { 152 return EqualPredicate.getInstance(value); 153 } 154 155 164 public static Predicate identityPredicate(Object value) { 165 return IdentityPredicate.getInstance(value); 166 } 167 168 179 public static Predicate instanceofPredicate(Class type) { 180 return InstanceofPredicate.getInstance(type); 181 } 182 183 194 public static Predicate uniquePredicate() { 195 return UniquePredicate.getInstance(); 197 } 198 199 216 public static Predicate invokerPredicate(String methodName){ 217 return asPredicate(InvokerTransformer.getInstance(methodName)); 219 } 220 221 241 public static Predicate invokerPredicate(String methodName, Class [] paramTypes, Object [] args){ 242 return asPredicate(InvokerTransformer.getInstance(methodName, paramTypes, args)); 244 } 245 246 249 260 public static Predicate andPredicate(Predicate predicate1, Predicate predicate2) { 261 return AndPredicate.getInstance(predicate1, predicate2); 262 } 263 264 276 public static Predicate allPredicate(Predicate[] predicates) { 277 return AllPredicate.getInstance(predicates); 278 } 279 280 292 public static Predicate allPredicate(Collection predicates) { 293 return AllPredicate.getInstance(predicates); 294 } 295 296 307 public static Predicate orPredicate(Predicate predicate1, Predicate predicate2) { 308 return OrPredicate.getInstance(predicate1, predicate2); 309 } 310 311 323 public static Predicate anyPredicate(Predicate[] predicates) { 324 return AnyPredicate.getInstance(predicates); 325 } 326 327 339 public static Predicate anyPredicate(Collection predicates) { 340 return AnyPredicate.getInstance(predicates); 341 } 342 343 354 public static Predicate eitherPredicate(Predicate predicate1, Predicate predicate2) { 355 return onePredicate(new Predicate[] { predicate1, predicate2 }); 356 } 357 358 370 public static Predicate onePredicate(Predicate[] predicates) { 371 return OnePredicate.getInstance(predicates); 372 } 373 374 386 public static Predicate onePredicate(Collection predicates) { 387 return OnePredicate.getInstance(predicates); 388 } 389 390 401 public static Predicate neitherPredicate(Predicate predicate1, Predicate predicate2) { 402 return nonePredicate(new Predicate[] { predicate1, predicate2 }); 403 } 404 405 417 public static Predicate nonePredicate(Predicate[] predicates) { 418 return NonePredicate.getInstance(predicates); 419 } 420 421 433 public static Predicate nonePredicate(Collection predicates) { 434 return NonePredicate.getInstance(predicates); 435 } 436 437 447 public static Predicate notPredicate(Predicate predicate) { 448 return NotPredicate.getInstance(predicate); 449 } 450 451 454 465 public static Predicate asPredicate(Transformer transformer) { 466 return TransformerPredicate.getInstance(transformer); 467 } 468 469 472 483 public static Predicate nullIsExceptionPredicate(Predicate predicate){ 484 return NullIsExceptionPredicate.getInstance(predicate); 485 } 486 487 498 public static Predicate nullIsFalsePredicate(Predicate predicate){ 499 return NullIsFalsePredicate.getInstance(predicate); 500 } 501 502 513 public static Predicate nullIsTruePredicate(Predicate predicate){ 514 return NullIsTruePredicate.getInstance(predicate); 515 } 516 517 531 public static Predicate transformedPredicate(Transformer transformer, Predicate predicate) { 532 return TransformedPredicate.getInstance(transformer, predicate); 533 } 534 535 } 536 | Popular Tags |