net.sf.staccatocommons.lang.thunk
Class Thunks

java.lang.Object
  extended by net.sf.staccatocommons.lang.thunk.Thunks

public class Thunks
extends Object

Class factory methods for some common Thunks

Author:
flbulgarelli

Method Summary
static
<A> net.sf.staccatocommons.defs.Thunk<A>
constant(A value)
          Returns a thunk that returns always the given value
static net.sf.staccatocommons.defs.Thunk<Date> currentDate()
          Returns a Thunk that provides the current date
static
<A> net.sf.staccatocommons.defs.Thunk<A>
fail(String message, Object... args)
          Answers a Thunk that, when evaluated, throws an exception with the given formatted message as Ensure.fail(String, Object...)
static
<A> net.sf.staccatocommons.defs.Thunk<A>
from(Callable<A> callable)
          Returns a thunk whose value is retrieved sending Callable.call() to the given Callable
static net.sf.staccatocommons.defs.Thunk<Void> from(Runnable runnable)
          Returns a cell that provides not actual value, but a side effect instead, by sending Runnable.run() to the given runnable
static
<A> net.sf.staccatocommons.defs.Thunk<A>
null_()
          Returns a constant Thunk that always provides null
static
<A> net.sf.staccatocommons.defs.Thunk<A>
undefined()
          Returns a thunk that when evaluated throws a RuntimeException.
static
<A> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.Thunk<A>,A>
value()
          Returns a Function that evaluates its Thunk argument
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

constant

public static <A> net.sf.staccatocommons.defs.Thunk<A> constant(A value)
Returns a thunk that returns always the given value

Type Parameters:
A -
Parameters:
value - the value the constant thunk will return as when invoking Thunk.value()
Returns:
a new thunk

null_

@Constant
public static <A> net.sf.staccatocommons.defs.Thunk<A> null_()
Returns a constant Thunk that always provides null

Type Parameters:
A -
Returns:
a constant thunk of nulls

currentDate

@Constant
public static net.sf.staccatocommons.defs.Thunk<Date> currentDate()
Returns a Thunk that provides the current date

Returns:
a constant thunk that provides new Date()

from

public static <A> net.sf.staccatocommons.defs.Thunk<A> from(@NonNull
                                                            Callable<A> callable)
Returns a thunk whose value is retrieved sending Callable.call() to the given Callable

Type Parameters:
A -
Parameters:
callable -
Returns:
a new Thunk that wraps the given callable

undefined

@Constant
public static <A> net.sf.staccatocommons.defs.Thunk<A> undefined()
Returns a thunk that when evaluated throws a RuntimeException. This Thunk is said to have an undefined element.

Type Parameters:
A -
Returns:
a Constant undefined thunk

fail

public static <A> net.sf.staccatocommons.defs.Thunk<A> fail(@NonNull
                                                            String message,
                                                            Object... args)
Answers a Thunk that, when evaluated, throws an exception with the given formatted message as Ensure.fail(String, Object...)

Parameters:
message - the message
args - the message arguments
Returns:
a new Thunk that fails with the given message

from

public static net.sf.staccatocommons.defs.Thunk<Void> from(@NonNull
                                                           Runnable runnable)
Returns a cell that provides not actual value, but a side effect instead, by sending Runnable.run() to the given runnable

Parameters:
runnable -
Returns:
a new Thunk that wraps the given Runnable

value

@Constant
public static <A> net.sf.staccatocommons.defs.function.Function<net.sf.staccatocommons.defs.Thunk<A>,A> value()
Returns a Function that evaluates its Thunk argument

Type Parameters:
A -
Returns:
a constant Function


Copyright © 2010-2012 Staccatocommons. All Rights Reserved.