org.apache.commons.collections4.functors

## Class IfClosure<E>

- java.lang.Object
- - org.apache.commons.collections4.functors.IfClosure<E>

- All Implemented Interfaces:
    Serializable, Closure<E>

      public class IfClosure<E>
      extends Object
      implements Closure<E>, Serializable

  Closure implementation acts as an if statement calling one or other closure based on a predicate.
  Since:
    3.0
  Version:
    $Id: IfClosure.java 1686855 2015-06-22 13:00:27Z tn $
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `IfClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure)` Constructor that performs no validation.
    `IfClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure, Closure<? super E> falseClosure)` Constructor that performs no validation.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `execute(E input)` Executes the true or false closure according to the result of the predicate.
    `Closure<? super E>` | `getFalseClosure()` Gets the closure called when false.
    `Predicate<? super E>` | `getPredicate()` Gets the predicate.
    `Closure<? super E>` | `getTrueClosure()` Gets the closure called when true.
    `static <E> Closure<E>` | `ifClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure)` Factory method that performs validation.
    `static <E> Closure<E>` | `ifClosure(Predicate<? super E> predicate, Closure<? super E> trueClosure, Closure<? super E> falseClosure)` Factory method that performs validation.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### IfClosure

          public IfClosure(Predicate<? super E> predicate,
                   Closure<? super E> trueClosure)

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

      This constructor creates a closure that performs no action when the predicate is false.

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

    - #### IfClosure

          public IfClosure(Predicate<? super E> predicate,
                   Closure<? super E> trueClosure,
                   Closure<? super E> falseClosure)

      Constructor that performs no validation. Use `ifClosure` 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

    - #### ifClosure

          public static <E> Closure<E> ifClosure(Predicate<? super E> predicate,
                                 Closure<? super E> trueClosure)

      Factory method that performs validation.

      This factory creates a closure that performs no action when the predicate is false.

      Type Parameters:
        `E` - the type that the closure acts on
      Parameters:
        `predicate` - predicate to switch on
        `trueClosure` - closure used if true
      Returns:
        the `if` closure
      Throws:
        `NullPointerException` - if either argument is null
      Since:
        3.2

    - #### ifClosure

          public static <E> Closure<E> ifClosure(Predicate<? super E> predicate,
                                 Closure<? super E> trueClosure,
                                 Closure<? super E> falseClosure)

      Factory method that performs validation.
      Type Parameters:
        `E` - the type that the closure acts on
      Parameters:
        `predicate` - predicate to switch on
        `trueClosure` - closure used if true
        `falseClosure` - closure used if false
      Returns:
        the `if` closure
      Throws:
        `NullPointerException` - if any argument is null

    - #### execute

          public void execute(E input)

      Executes the true or false closure according to the result of the predicate.
      Specified by:
        `execute` in interface `Closure<E>`
      Parameters:
        `input` - the input object

    - #### getPredicate

          public Predicate<? super E> getPredicate()

      Gets the predicate.
      Returns:
        the predicate
      Since:
        3.1

    - #### getTrueClosure

          public Closure<? super E> getTrueClosure()

      Gets the closure called when true.
      Returns:
        the closure
      Since:
        3.1

    - #### getFalseClosure

          public Closure<? super E> getFalseClosure()

      Gets the closure called when false.
      Returns:
        the closure
      Since:
        3.1

Copyright © 2001–2015 The Apache Software Foundation. All rights reserved.