jpaul.Misc
Class Predicate<T>

java.lang.Object
  extended by jpaul.Misc.Predicate<T>
Direct Known Subclasses:
SetMembership

public abstract class Predicate<T>
extends java.lang.Object

Predicate wraps a boolean predicate.

Version:
$Id: Predicate.java,v 1.4 2005/10/05 16:33:10 salcianu Exp $
Author:
Alexandru Salcianu - salcianu@alum.mit.edu

Constructor Summary
Predicate()
           
 
Method Summary
static
<T> Predicate<T>
AND(Predicate<T> a, Predicate<T> b)
          Short-circuited AND operation.
abstract  boolean check(T obj)
          The real predicate.
static
<T> Predicate<T>
FALSE()
          Returns an always-false predicate.
static
<T> Predicate<T>
FULL_AND(Predicate<T> a, Predicate<T> b)
          Complete AND operation.
static
<T> Predicate<T>
FULL_OR(Predicate<T> a, Predicate<T> b)
          Complete OR operation.
static
<T> Predicate<T>
NOT(Predicate<T> pred)
          Predicate negation.
static
<T> Predicate<T>
OR(Predicate<T> a, Predicate<T> b)
          Short-circuited OR operation.
static
<T> Predicate<T>
TRUE()
          Returns an always-true predicate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Predicate

public Predicate()
Method Detail

check

public abstract boolean check(T obj)
The real predicate.


TRUE

public static <T> Predicate<T> TRUE()
Returns an always-true predicate.


FALSE

public static <T> Predicate<T> FALSE()
Returns an always-false predicate.


NOT

public static <T> Predicate<T> NOT(Predicate<T> pred)
Predicate negation.

Returns:
A predicate that is true iff pred is false.

AND

public static <T> Predicate<T> AND(Predicate<T> a,
                                   Predicate<T> b)
Short-circuited AND operation.

Returns:
A predicate that is true iff both a and b are true. Evaluation stops as soon as the final result is known.

OR

public static <T> Predicate<T> OR(Predicate<T> a,
                                  Predicate<T> b)
Short-circuited OR operation.

Returns:
A predicate that is false iff both a and b are false. Evaluation stops as soon as the final result is known.

FULL_AND

public static <T> Predicate<T> FULL_AND(Predicate<T> a,
                                        Predicate<T> b)
Complete AND operation. Similar to AND(jpaul.Misc.Predicate, jpaul.Misc.Predicate) but no short-circuit: in all situations, a is evaluated and next b is evaluated. Good for impure predicates.


FULL_OR

public static <T> Predicate<T> FULL_OR(Predicate<T> a,
                                       Predicate<T> b)
Complete OR operation. Similar to OR(jpaul.Misc.Predicate, jpaul.Misc.Predicate) but no short-circuit: in all situations, a is evaluated and next b is evaluated. Good for impure predicates.



Copyright 2005 Alexandru Salcianu - salcianu@alum.mit.edu