|
package swensen.functional;
/**
* Provides compatibility between Action0 and Runnable.
* @author Stephen Swensen
*/
public abstract class RunnableAction implements Action0, Runnable {
/**
* Invokes this.call(), cannot be overridden, instead override call().
*/
public final void run() {
call();
}
/**
* Create a RunnableAction from an Action0.
* @param action the Action0 to wrap.
* @return a new RunnableAction.
*/
public static RunnableAction from(final Action0 action)
{
if(action == null)
throw new NullPointerException("action");
return new RunnableAction() {
public void call() {
action.call();
}
};
}
/**
* Create a RunnableAction from a Runnable.
* @param runnable the Runnable to wrap, not null.
* @return a new RunnableAction.
*/
public static RunnableAction from(final Runnable runnable)
{
if(runnable == null)
throw new NullPointerException("runnable");
return new RunnableAction() {
public void call() {
runnable.run();
}
};
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm developing Unquote, a library for writing unit test assertions as F# quoted expressions: http://code.google.com/p/unquote/
I am working through Project Euler with F#: http://projecteulerfun.blogspot.com/
I participate in Stack Overflow: http://stackoverflow.com/users/236255/stephen-swensen