jpaul.Misc
Class ActionPredicate<T>

java.lang.Object
  extended by jpaul.Misc.ActionPredicate<T>
All Implemented Interfaces:
Action<T>

public abstract class ActionPredicate<T>
extends java.lang.Object
implements Action<T>

ActionPredicate is a combination of an Action and a Predicate. Intuitively, one may say that ActionPredicate is an impure predicate, but one should be aware of the fact that ActionPredicate and Predicate are not iin any subclassing relationship (in general, it is a bad software engineering practice to have subclassing between pure and impure varieties of the same concept). Still, we provide a static method (fromPredicate(jpaul.Misc.Predicate)) that converts a Predicate into an ActionPredicate.

Version:
$Id: ActionPredicate.java,v 1.4 2006/03/14 02:29:31 salcianu Exp $
Author:
Alex Salcianu - salcianu@alum.mit.edu
See Also:
Action, Predicate

Constructor Summary
ActionPredicate()
           
 
Method Summary
 void action(T obj)
          Action: executes actionPredicate(T) only for its side-effects, ignoring its result.
abstract  boolean actionPredicate(T obj)
          A boolean predicate WITH possible side-effects.
static
<T> ActionPredicate<T>
fromAction(Action<T> action, boolean predicateResult)
          Creates an ActionPredicate whose actionPredicate method first invokes the action from action and next returns the constant boolean value predicateResult.
static
<T> ActionPredicate<T>
fromPredicate(Predicate<T> predicate)
          Creates an ActionPredicate wrapper around a Predicate: it does not perform any side-effect, it just returns the boolean value of teh predicate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ActionPredicate

public ActionPredicate()
Method Detail

actionPredicate

public abstract boolean actionPredicate(T obj)
A boolean predicate WITH possible side-effects.


action

public final void action(T obj)
Action: executes actionPredicate(T) only for its side-effects, ignoring its result.

Specified by:
action in interface Action<T>

fromAction

public static <T> ActionPredicate<T> fromAction(Action<T> action,
                                                boolean predicateResult)
Creates an ActionPredicate whose actionPredicate method first invokes the action from action and next returns the constant boolean value predicateResult.


fromPredicate

public static <T> ActionPredicate<T> fromPredicate(Predicate<T> predicate)
Creates an ActionPredicate wrapper around a Predicate: it does not perform any side-effect, it just returns the boolean value of teh predicate.



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