Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.apache.commons.collections.functors
Class IfClosure

    java.lang.Object
      |
      +--org.apache.commons.collections.functors.IfClosure

All Implemented Interfaces:
  Closure, Serializable

public class IfClosure
extends Object
implements Closure, Serializable

Closure implementation acts as an if statement calling one or other closure based on a predicate.

Since:
  Commons Collections 3.0
Version:
  $Revision: 1.6 $ $Date: 2004/05/16 11:47:38 $
Author:
  Stephen Colebourne
See Also:
  Serialized Form

Constructor Summary
`IfClosure(Predicate predicate, Closure trueClosure, Closure falseClosure)` Constructor that performs no validation.

Method Summary
`void` | `execute(Object input)` Executes the true or false closure accoring to the result of the predicate.
`Closure` | `getFalseClosure()` Gets the closure called when false.
`static Closure` | `getInstance(Predicate predicate, Closure trueClosure, Closure falseClosure)` Factory method that performs validation.
`Predicate` | `getPredicate()` Gets the predicate.
`Closure` | `getTrueClosure()` Gets the closure called when true.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### IfClosure

    public IfClosure(Predicate predicate,
                     Closure trueClosure,
                     Closure falseClosure)

  Constructor that performs no validation. Use `getInstance` if you want that.

Parameters:
  `predicate` - predicate to switch on, not null
  `trueClosure` - closure used if true, not null
  `falseClosure` - closure used if false, not null

Method Detail

### getInstance

    public static Closure getInstance(Predicate predicate,
                                      Closure trueClosure,
                                      Closure falseClosure)

  Factory method that performs validation.

  Parameters:
    `predicate` - predicate to switch on
    `trueClosure` - closure used if true
    `falseClosure` - closure used if false
  Returns:
    the `if` closure
  Throws:
    `IllegalArgumentException` - if any argument is null

### execute

    public void execute(Object input)

  Executes the true or false closure accoring to the result of the predicate.

  Specified by:
    `execute` in interface `Closure`
  Parameters:
    `input` - the input object

### getPredicate

    public Predicate getPredicate()

  Gets the predicate.

  Returns:
    the predicate
  Since:
    Commons Collections 3.1

### getTrueClosure

    public Closure getTrueClosure()

  Gets the closure called when true.

  Returns:
    the closure
  Since:
    Commons Collections 3.1

### getFalseClosure

    public Closure getFalseClosure()

  Gets the closure called when false.

  Returns:
    the closure
  Since:
    Commons Collections 3.1

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 2001-2004 Apache Software Foundation. All Rights Reserved.