de.unkrig.commons.lang.protocol
Class RunnableUtil

java.lang.Object
  extended by de.unkrig.commons.lang.protocol.RunnableUtil

public final class RunnableUtil
extends java.lang.Object

Various Runnable-related utility methods.


Field Summary
static java.lang.Runnable NOP
          A Runnable that does simply nothing.
 
Method Summary
static
<EX extends java.lang.RuntimeException>
java.lang.Runnable
asRunnable(RunnableWhichThrows<EX> delegate)
          Converts a RunnableWhichThrows into a Runnable, which is possible iff the source runnable's exception is a subclass of RuntimeException.
static
<EX extends java.lang.Exception>
RunnableWhichThrows<EX>
asRunnableWhichThrows(java.lang.Runnable delegate)
          Converts a Runnable into a RunnableWhichThrows.
static
<EX extends java.lang.Exception>
RunnableWhichThrows<EX>
runSequentially(java.util.Collection<RunnableWhichThrows<EX>> delegates)
          Runs the given delegates in the current thread, in the order of the collection's iterator.
static
<EX extends java.lang.Exception>
RunnableWhichThrows<EX>
runSequentially(RunnableWhichThrows<EX> delegate1, RunnableWhichThrows<EX> delegate2)
          Runs delegate1, then delegate2 in the current thread.
static
<ST> java.lang.Runnable
sparingRunnable(java.lang.Runnable delegate, Predicate<ST> condition, ST subject)
          The returned Runnable runs the delegate iff the condition evaluates to true.
static java.lang.Runnable sparingRunnable(java.lang.Runnable delegate, Producer<java.lang.Boolean> condition)
          The returned Runnable runs the delegate iff the condition produces Boolean.TRUE.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NOP

public static final java.lang.Runnable NOP
A Runnable that does simply nothing.

Method Detail

runSequentially

public static <EX extends java.lang.Exception> RunnableWhichThrows<EX> runSequentially(RunnableWhichThrows<EX> delegate1,
                                                                                       RunnableWhichThrows<EX> delegate2)
Runs delegate1, then delegate2 in the current thread.

Returns:
A runnable that runs delegate1 and then delegate2
See Also:
RunnableWhichThrows.run()

runSequentially

public static <EX extends java.lang.Exception> RunnableWhichThrows<EX> runSequentially(java.util.Collection<RunnableWhichThrows<EX>> delegates)
Runs the given delegates in the current thread, in the order of the collection's iterator.

Returns:
A runnable that runs all the delegates in strict sequence
See Also:
RunnableWhichThrows.run()

asRunnable

public static <EX extends java.lang.RuntimeException> java.lang.Runnable asRunnable(RunnableWhichThrows<EX> delegate)
Converts a RunnableWhichThrows into a Runnable, which is possible iff the source runnable's exception is a subclass of RuntimeException.

Type Parameters:
EX - The source runnable's exception

asRunnableWhichThrows

public static <EX extends java.lang.Exception> RunnableWhichThrows<EX> asRunnableWhichThrows(java.lang.Runnable delegate)
Converts a Runnable into a RunnableWhichThrows.


sparingRunnable

public static <ST> java.lang.Runnable sparingRunnable(java.lang.Runnable delegate,
                                                      Predicate<ST> condition,
                                                      ST subject)
The returned Runnable runs the delegate iff the condition evaluates to true.

(The condition is evaluated with null as the subject argument.)

Parameters:
subject - The subject for the condition

sparingRunnable

public static java.lang.Runnable sparingRunnable(java.lang.Runnable delegate,
                                                 Producer<java.lang.Boolean> condition)
The returned Runnable runs the delegate iff the condition produces Boolean.TRUE.

See Also:
PredicateUtil.after(long), ProducerUtil.every(long)