Class Callbacks


  • public final class Callbacks
    extends java.lang.Object
    Misc methods that can be used as callbacks.
    • Constructor Summary

      Constructors 
      Constructor Description
      Callbacks()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> void doNothing​(T ignored)
      Empty consumer.
      static <T> T identity​(T input)
      Identity Function.
      static void invokeSafely​(RunnableWithException runnable, java.util.function.Consumer<java.lang.Throwable> failureHandler)
      Invokes the given RunnableWithException and catches any exceptions that it may throw.
      static <T1,​T2>
      void
      invokeSafely​(java.util.function.BiConsumer<T1,​T2> consumer, T1 argument1, T2 argument2, java.util.function.Consumer<java.lang.Throwable> failureHandler)
      Invokes the given Consumer with the given argument, and catches any exceptions that it may throw.
      static <T> void invokeSafely​(java.util.function.Consumer<T> consumer, T argument, java.util.function.Consumer<java.lang.Throwable> failureHandler)
      Invokes the given Consumer with the given argument, and catches any exceptions that it may throw.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Callbacks

        public Callbacks()
    • Method Detail

      • doNothing

        public static <T> void doNothing​(T ignored)
        Empty consumer. Does nothing.
        Type Parameters:
        T - Return type. Ignored.
        Parameters:
        ignored - Ignored argument.
      • identity

        public static <T> T identity​(T input)
        Identity Function.
        Type Parameters:
        T - Type of the input.
        Parameters:
        input - The input.
        Returns:
        The input.
      • invokeSafely

        public static <T> void invokeSafely​(java.util.function.Consumer<T> consumer,
                                            T argument,
                                            java.util.function.Consumer<java.lang.Throwable> failureHandler)
        Invokes the given Consumer with the given argument, and catches any exceptions that it may throw.
        Type Parameters:
        T - The type of the argument.
        Parameters:
        consumer - The consumer to invoke.
        argument - The argument to pass to the consumer.
        failureHandler - An optional callback to invoke if the consumer threw any exceptions.
        Throws:
        java.lang.NullPointerException - If the consumer is null.
      • invokeSafely

        public static <T1,​T2> void invokeSafely​(java.util.function.BiConsumer<T1,​T2> consumer,
                                                      T1 argument1,
                                                      T2 argument2,
                                                      java.util.function.Consumer<java.lang.Throwable> failureHandler)
        Invokes the given Consumer with the given argument, and catches any exceptions that it may throw.
        Type Parameters:
        T1 - The type of the first argument.
        T2 - The type of the second argument.
        Parameters:
        consumer - The consumer to invoke.
        argument1 - The first argument to pass to the consumer.
        argument2 - The second argument to pass to the consumer.
        failureHandler - An optional callback to invoke if the consumer threw any exceptions.
        Throws:
        java.lang.NullPointerException - If the consumer is null.