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 Summary

      Fields 
      Modifier and Type Field Description
      static Predicate<java.lang.Object> FALSE
      A predicate that always returns false, regardless of the input object.
      static Predicate<java.lang.Object> TRUE
      A predicate that always returns true, regardless of the input object.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      static <T> Predicate<T> alwaysFalse()
      A predicate that always returns false, regardless of the input object.
      static <T> Predicate<T> alwaysTrue()
      A predicate that always returns true, regardless of the input object.
      boolean apply​(T t)
      Tests the given value.
      static <T> Predicate<T> from​(java.util.function.Predicate<T> predicate)
      Creates a predicate from a JDK predicate.
      static <T> Predicate<T> fromGuava​(com.google.common.base.Predicate<T> predicate)
      Creates a predicate from a Guava predicate.
      default <O> Function<T,​O> function​(O onTrue, O onFalse)
      Creates a function the returns one of the given values.
      default com.google.common.base.Predicate<T> toGuavaPredicate()
      Creates a Guava Predicate from this predicate.
      default java.util.function.Predicate<T> toPredicate()
      Creates a JDK Predicate from this predicate.
    • Field Detail

      • TRUE

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

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

      • apply

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

        default java.util.function.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​(java.util.function.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