Class Functions

java.lang.Object
com.ocient.util.Functions

public class Functions extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static <A, R> Function<A,R>
    Returns a function that always returns a constant value.
    static <A, B, R> BiFunction<A,B,R>
    Returns a function that always returns a constant value.
    static boolean
    A function that always returns false.
    static <T> boolean
    A function that always returns false, regardless of the argument.
    static <T, U> boolean
    alwaysFalse(T t, U u)
    A function that always returns false, regardless of the argument.
    static <A, B> A
    alwaysFirst(A a, B b)
    Returns the first argument of type A.
    static <A, B> B
    alwaysSecond(A a, B b)
    Returns the second argument of type B.
    static boolean
    A function that always returns true.
    static <T> boolean
    A function that always returns true, regardless of the argument.
    static <T, U> boolean
    alwaysTrue(T t, U u)
    A function that always returns true, regardless of the argument.
    static <A, R> Function<A,R>
    constant(R r)
    Returns a function that always returns the given constant value, regardless of its input.
    static <A, B, R> BiFunction<A,B,R>
    constant2(R r)
    Returns a function that always returns the given constant value, regardless of its input arguments.
    static <T> T
    identity(T t)
    A function that returns its argument unchanged.
    static boolean
    negate(boolean b)
    Returns the logical negation of the boolean argument.
    static <T> Function<T,Boolean>
    negate(Function<T,Boolean> predicate)
    Returns a composed predicate that represents the logical negation of the given function.
    static void
    A function that does nothing.
    static <T> void
    noop(T t)
    A function that does nothing with the given argument.
    static <T, U> void
    noop(T t, U u)
    A function that does nothing with the given arguments.
    static Void
    A function that returns a Void.
    static <T> Void
    A function that does nothing with the given argument.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • noop

      public static void noop()
      A function that does nothing.
    • noop

      public static <T> void noop(T t)
      A function that does nothing with the given argument.
      Type Parameters:
      T - the type of the argument
      Parameters:
      t - the argument to ignore
    • noopBoxedVoid

      public static Void noopBoxedVoid()
      A function that returns a Void.
    • noopBoxedVoid

      public static <T> Void noopBoxedVoid(T t)
      A function that does nothing with the given argument.
      Type Parameters:
      T - the type of the argument
      Parameters:
      t - the argument to ignore
    • noop

      public static <T, U> void noop(T t, U u)
      A function that does nothing with the given arguments.
      Type Parameters:
      T - the type of the first argument
      U - the type of the second argument
      Parameters:
      t - the first argument to ignore
      u - the second argument to ignore
    • constant

      public static <A, R> Function<A,R> constant(R r)
      Returns a function that always returns the given constant value, regardless of its input.
      Type Parameters:
      A - the type of the input to the function
      R - the type of the constant value to return
      Parameters:
      r - the constant value to return
      Returns:
      a function that always returns the given constant value
    • constant2

      public static <A, B, R> BiFunction<A,B,R> constant2(R r)
      Returns a function that always returns the given constant value, regardless of its input arguments.
      Type Parameters:
      A - the type of the first input argument to the function
      B - the type of the second input argument to the function
      R - the type of the constant value to return
      Parameters:
      r - the constant value to return
      Returns:
      a function that always returns the given constant value
    • alwaysTrue

      public static boolean alwaysTrue()
      A function that always returns true.
      Returns:
      always true
    • alwaysTrue

      public static <T> boolean alwaysTrue(T t)
      A function that always returns true, regardless of the argument.
      Type Parameters:
      T - the type of the argument
      Parameters:
      t - the argument (ignored)
      Returns:
      always true
    • alwaysTrue

      public static <T, U> boolean alwaysTrue(T t, U u)
      A function that always returns true, regardless of the argument.
      Type Parameters:
      T - the type of the argument
      U - the type of the argument
      Parameters:
      t - the argument (ignored)
      u - the argument (ignored)
      Returns:
      always true
    • alwaysFalse

      public static boolean alwaysFalse()
      A function that always returns false.
      Returns:
      always false
    • alwaysFalse

      public static <T> boolean alwaysFalse(T t)
      A function that always returns false, regardless of the argument.
      Type Parameters:
      T - the type of the argument
      Parameters:
      t - the argument (ignored)
      Returns:
      always false
    • alwaysFalse

      public static <T, U> boolean alwaysFalse(T t, U u)
      A function that always returns false, regardless of the argument.
      Type Parameters:
      T - the type of the argument
      U - the type of the argument
      Parameters:
      t - the argument (ignored)
      u - the argument (ignored)
      Returns:
      always false
    • alwaysFirst

      public static <A, B> A alwaysFirst(A a, B b)
      Returns the first argument of type A.
      Parameters:
      a - the first argument of type A
      b - the second argument of type B
      Returns:
      the first argument of type A
    • alwaysSecond

      public static <A, B> B alwaysSecond(A a, B b)
      Returns the second argument of type B.
      Parameters:
      a - the first argument of type A
      b - the second argument of type B
      Returns:
      the second argument of type B
    • identity

      public static <T> T identity(T t)
      A function that returns its argument unchanged.
      Type Parameters:
      T - the type of the argument
      Parameters:
      t - the argument
      Returns:
      the argument
    • negate

      public static boolean negate(boolean b)
      Returns the logical negation of the boolean argument.
      Parameters:
      b - the boolean to negate
      Returns:
      the negation of the boolean argument
    • negate

      public static <T> Function<T,Boolean> negate(Function<T,Boolean> predicate)
      Returns a composed predicate that represents the logical negation of the given function. The resulting function returns true when the given function returns false and vice versa.
      Type Parameters:
      T - the type of the input to the function
      Parameters:
      predicate - the function to negate
      Returns:
      a function that represents the logical negation of the given function
    • always1

      public static <A, R> Function<A,R> always1(Supplier<R> f)
      Returns a function that always returns a constant value. The function takes one argument of type A, but the value is ignored, and the constant value is returned instead.
      Type Parameters:
      A - the type of the argument (ignored)
      R - the type of the constant value
      Parameters:
      f - the supplier of the constant value
      Returns:
      a function that always returns the constant value
    • always2

      public static <A, B, R> BiFunction<A,B,R> always2(Supplier<R> f)
      Returns a function that always returns a constant value. The function takes two arguments of types A and B, but the values are ignored, and the constant value is returned instead.
      Type Parameters:
      A - the type of the first argument (ignored)
      B - the type of the second argument (ignored)
      R - the type of the constant value
      Parameters:
      f - the supplier of the constant value
      Returns:
      a function that always returns the constant value