mdb suggests this approach.
Seems fine, even if this is the only method ever in this class. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2548 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
|
||||||
|
package com.samskivert.util;
|
||||||
|
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities for Callables.
|
||||||
|
*/
|
||||||
|
public class Callables
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Return a {@link Callable} that merely returns the specified value.
|
||||||
|
* No exception will ever be thrown.
|
||||||
|
*/
|
||||||
|
public static <V> Callable<V> asCallable (final V value)
|
||||||
|
{
|
||||||
|
return new Callable<V>() {
|
||||||
|
public V call () {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
//
|
|
||||||
// $Id$
|
|
||||||
|
|
||||||
package com.samskivert.util;
|
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Callable that just returns a predefined value.
|
|
||||||
*/
|
|
||||||
public class ValueCallable<V>
|
|
||||||
implements Callable<V>
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Factory to create a ValueCallable from a value while avoiding having to specify the type.
|
|
||||||
* TODO: I think I want <? super V> in the return value, not sure how to make it.
|
|
||||||
*/
|
|
||||||
public static <V> ValueCallable<V> create (V value)
|
|
||||||
{
|
|
||||||
return new ValueCallable<V>(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct a ValueCallable.
|
|
||||||
*/
|
|
||||||
public ValueCallable (V value)
|
|
||||||
{
|
|
||||||
_value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// from interface Callable
|
|
||||||
public V call ()
|
|
||||||
{
|
|
||||||
return _value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** The value we'll be returning. */
|
|
||||||
protected V _value;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user