Class PredicateDrivenFunction<T,​U>

Type Parameters:
T - type of input accepted by this function
U - type of output produced by this function
All Implemented Interfaces:

public class PredicateDrivenFunction<T,​U>
extends Object
implements Function<T,​U>
A Function that runs a Predicate and then runs one of two other possible functions based on the result.

If either function is null, the result will be null if that function were needed.

  • Field Details

    • predicate

      @Nonnull private final Predicate<? super T> predicate
      A predicate to apply.
    • trueFunction

      @Nullable private final Function<? super T,​U> trueFunction
      Function to apply if predicate is true.
    • falseFunction

      @Nullable private final Function<? super T,​U> falseFunction
      Function to apply if predicate is false.
  • Constructor Details

    • PredicateDrivenFunction

      public PredicateDrivenFunction​(@Nonnull @ParameterName(name="condition") Predicate<? super T> condition, @Nullable @ParameterName(name="whenTrue") Function<? super T,​U> whenTrue, @Nullable @ParameterName(name="whenFalse") Function<? super T,​U> whenFalse)
      condition - predicate to apply
      whenTrue - function to apply if predicate evaluates to true
      whenFalse - function to apply if predicate evaluates to false
  • Method Details

    • apply

      public U apply​(@Nullable T input)
      Specified by:
      apply in interface Function<T,​U>