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:
    Function<T,​U>

    @ThreadSafe
    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.

    Since:
    8.2.0
    • Field Detail

      • 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 Detail

      • 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)
        Constructor.
        Parameters:
        condition - predicate to apply
        whenTrue - function to apply if predicate evaluates to true
        whenFalse - function to apply if predicate evaluates to false
    • Method Detail

      • apply

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