Package ratpack.func

Interface Predicate<T>

  • Type Parameters:
    T - the type of object “tested” by the predicate
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface Predicate<T>
    A function that returns true or false for a value.

    This type serves the same purpose as the JDK's Predicate, but allows throwing checked exceptions. It contains methods for bridging to and from the JDK type.

    • Field Detail

      • TRUE

        static final Predicate<Object> TRUE
        A predicate that always returns true, regardless of the input object.
        Since:
        1.1
      • FALSE

        static final Predicate<Object> FALSE
        A predicate that always returns false, regardless of the input object.
        Since:
        1.1
    • Method Detail

      • apply

        boolean apply​(T t)
               throws Exception
        Tests the given value.
        Parameters:
        t - the value to “test”
        Returns:
        true if the predicate applied, otherwise false
        Throws:
        Exception - any
      • toPredicate

        default Predicate<T> toPredicate()
        Creates a JDK Predicate from this predicate.

        Any exceptions thrown by this action will be unchecked via Exceptions.uncheck(Throwable) and rethrown.

        Returns:
        this function as a JDK style predicate.
      • toGuavaPredicate

        default com.google.common.base.Predicate<T> toGuavaPredicate()
        Creates a Guava Predicate from this predicate.

        Any exceptions thrown by this action will be unchecked via Exceptions.uncheck(Throwable) and rethrown.

        Returns:
        this function as a Guava style predicate.
      • from

        static <T> Predicate<T> from​(Predicate<T> predicate)
        Creates a predicate from a JDK predicate.
        Type Parameters:
        T - the type of object this predicate tests
        Parameters:
        predicate - the JDK predicate
        Returns:
        the given JDK predicate as a predicate
      • fromGuava

        static <T> Predicate<T> fromGuava​(com.google.common.base.Predicate<T> predicate)
        Creates a predicate from a Guava predicate.
        Type Parameters:
        T - the type of object this predicate tests
        Parameters:
        predicate - the Guava predicate
        Returns:
        the given Guava predicate as a predicate
      • alwaysTrue

        static <T> Predicate<T> alwaysTrue()
        A predicate that always returns true, regardless of the input object.
        Type Parameters:
        T - the type of input object
        Returns:
        a predicate that always returns true
        Since:
        1.1
      • alwaysFalse

        static <T> Predicate<T> alwaysFalse()
        A predicate that always returns false, regardless of the input object.
        Type Parameters:
        T - the type of input object
        Returns:
        a predicate that always returns false
        Since:
        1.1
      • function

        default <O> Function<T,​O> function​(O onTrue,
                                                 O onFalse)
        Creates a function the returns one of the given values.
        Type Parameters:
        O - the output value
        Parameters:
        onTrue - the value to return if the predicate applies
        onFalse - the value to return if the predicate does not apply
        Returns:
        a function
        Since:
        1.5