public class JkRunnables
extends java.lang.Object
implements java.lang.Runnable
Runnable
. From this object you can replace the underlying Runnable
or
chain it with other ones.Modifier and Type | Method and Description |
---|---|
JkRunnables |
append(java.lang.Runnable... runnables)
Adds the specified
Runnable s at the end of the execution chain. |
JkRunnables |
append(java.lang.String name,
java.lang.Runnable runnable)
Adds the specified
Runnable at the end of the execution chain. |
JkRunnables |
appendIf(boolean condition,
java.lang.String name,
java.lang.Runnable runnable)
Same as
append(String, Runnable) but effective only the specified condition |
boolean |
contains(java.lang.String runnableName)
Returns
true if the execution chain contains a runnable with the
specified name. |
java.lang.Runnable |
getRunnable(int index)
Retrieves the
Runnable stored at the specified index in the execution chain. |
java.util.List<java.lang.String> |
getRunnableNames()
Returns the name of the
Runnable s, in the order of execution chain. |
int |
getSize()
Returns the total number of entries in the execution chain.
|
JkRunnables |
insertAfter(java.lang.String name,
java.lang.String afterRunnableName,
java.lang.Runnable runnable)
Inserts the specified runnable in the execution chain, just after another one.
|
JkRunnables |
insertBefore(java.lang.String name,
java.lang.String beforeRunnableName,
java.lang.Runnable runnable)
Inserts the specified runnable in the execution chain, just before another one.
|
static JkRunnables |
of()
Creates a
JkRunnables delegating to a no-op runnable. |
JkRunnables |
remove(java.lang.String runnableName)
Removes the runnable having the specified name, from the execution list.
|
JkRunnables |
replaceOrAppend(java.lang.String name,
java.lang.Runnable runnable)
Replaces the specified
Runnable with the same name in the execution chain, or appends it if not found. |
JkRunnables |
replaceOrInsertBefore(java.lang.String name,
java.lang.String beforeRunnableName,
java.lang.Runnable runnable)
Replaces a Runnable with the same name in the execution chain if exists,
otherwise inserts it before a specified runnable.
|
void |
run()
Executes the
Runnable s, in the order of the execution chain. |
JkRunnables |
setLogTasks(boolean log)
Sets if each runnable execution should be wrapped in a log task.
|
JkRunnables |
setTaskSuffix(java.lang.String suffix)
Sets the displayed suffix for the task.
|
public static JkRunnables of()
JkRunnables
delegating to a no-op runnable.public JkRunnables append(java.lang.String name, java.lang.Runnable runnable)
Runnable
at the end of the execution chain.name
- The name referencing the runnable. The name can be used to
remove the runnable form the chain or add others with place
relative to this one.remove(String)
,
insertBefore(String, String, Runnable)
,
insertAfter(String, String, Runnable)
,
contains(String)
public JkRunnables append(java.lang.Runnable... runnables)
Runnable
s at the end of the execution chain.public JkRunnables appendIf(boolean condition, java.lang.String name, java.lang.Runnable runnable)
append(String, Runnable)
but effective only the specified conditionpublic JkRunnables insertBefore(java.lang.String name, java.lang.String beforeRunnableName, java.lang.Runnable runnable)
name
- The name of the runnable to insert.beforeRunnableName
- The name of the runnable that we must insert before.runnable
- The runnable to insert.public JkRunnables replaceOrInsertBefore(java.lang.String name, java.lang.String beforeRunnableName, java.lang.Runnable runnable)
name
- The name referencing the runnable.beforeRunnableName
- The name of the runnable that the new runnable should be inserted before.runnable
- The runnable to replace or insert.java.lang.IllegalArgumentException
- if the Runnable is null.public JkRunnables insertAfter(java.lang.String name, java.lang.String afterRunnableName, java.lang.Runnable runnable)
name
- The name of the runnable to insert.afterRunnableName
- The name of the runnable that we must insert after.runnable
- The runnable to insert.public JkRunnables remove(java.lang.String runnableName)
runnableName
- The name of the runnable to remove.public JkRunnables replaceOrAppend(java.lang.String name, java.lang.Runnable runnable)
Runnable
with the same name in the execution chain, or appends it if not found.name
- The name referencing the runnable.runnable
- The Runnable
to replace or append.java.lang.IllegalArgumentException
- If the Runnable
is null.public java.util.List<java.lang.String> getRunnableNames()
Runnable
s, in the order of execution chain.public boolean contains(java.lang.String runnableName)
true
if the execution chain contains a runnable with the
specified name.public JkRunnables setLogTasks(boolean log)
public JkRunnables setTaskSuffix(java.lang.String suffix)
public int getSize()
public java.lang.Runnable getRunnable(int index)
Runnable
stored at the specified index in the execution chain.public void run()
Runnable
s, in the order of the execution chain.run
in interface java.lang.Runnable