net.sf.staccatocommons.lambda
Class LambdaFactory

java.lang.Object
  extended by net.sf.staccatocommons.lambda.LambdaFactory

public final class LambdaFactory
extends Object

LambdaFactorys are objects capable of creating simple Functions and Predicates of different arities in a DSL style, instead of implementing anonymous classes.

Author:
flbulgarelli

Constructor Summary
LambdaFactory(org.apache.commons.proxy.ProxyFactory proxyFactory)
          Creates a new LambdaFactory
 
Method Summary
<A> A
$(Class<A> clazz)
          Stubs a type for creating a lambda.
<A,B> net.sf.staccatocommons.defs.function.Function<A,B>
lambda(B returnType)
          Answers a Function that when applied sends to its argument the message previously sent to the last stubbed type.
<A> net.sf.staccatocommons.defs.predicate.Predicate<A>
lambda(boolean returnType)
          Answers a Predicate that when evaluated sends to its argument the message previously sent to the last stubbed type.
<A,B> net.sf.staccatocommons.defs.predicate.Predicate2<A,B>
lambda2(boolean returnType)
           
<A,B,C> net.sf.staccatocommons.defs.function.Function2<A,B,C>
lambda2(C returnType)
           
<A,B,C,D> net.sf.staccatocommons.defs.function.Function3<A,B,C,D>
lambda3(D returnType)
          Answers a Function3 that when applied sends to its first argument the message previously sent to the last stubbed type, passing its second argument as the first message argument, and its third argument to the second message argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LambdaFactory

public LambdaFactory(@NonNull
                     org.apache.commons.proxy.ProxyFactory proxyFactory)
Creates a new LambdaFactory

Method Detail

$

@NonNull
public <A> A $(@NonNull
                       Class<A> clazz)
Stubs a type for creating a lambda. The resulting stub must receive one and only one message. Not all LambdaFactorys can stub all types - ie, stubbing interfaces, concrete classes or final classes. Their stubbing capabilities depend on the ProxyFactory passed as constructor argument to this LambdaFactory

Type Parameters:
A -
Parameters:
clazz - the type to stub
Returns:
a new stub

lambda

@NonNull
public <A> net.sf.staccatocommons.defs.predicate.Predicate<A> lambda(boolean returnType)
Answers a Predicate that when evaluated sends to its argument the message previously sent to the last stubbed type. Refer to the use cases described in Lambda

Parameters:
returnType - meaningless, this argument is simply ignored
Returns:
a new AbstractPredicate
See Also:
Lambda

lambda

@NonNull
public <A,B> net.sf.staccatocommons.defs.function.Function<A,B> lambda(B returnType)
Answers a Function that when applied sends to its argument the message previously sent to the last stubbed type. Refer to the use cases described in Lambda

Parameters:
returnType - meaningless, this argument is simply ignored
Returns:
a new Function
See Also:
Lambda

lambda2

@NonNull
public <A,B,C> net.sf.staccatocommons.defs.function.Function2<A,B,C> lambda2(C returnType)

lambda2

@NonNull
public <A,B> net.sf.staccatocommons.defs.predicate.Predicate2<A,B> lambda2(boolean returnType)
See Also:
Lambda.lambda2(boolean)

lambda3

public <A,B,C,D> net.sf.staccatocommons.defs.function.Function3<A,B,C,D> lambda3(D returnType)
Answers a Function3 that when applied sends to its first argument the message previously sent to the last stubbed type, passing its second argument as the first message argument, and its third argument to the second message argument. Refer to the use cases described in Lambda

Parameters:
returnType - meaningless, this argument is simply ignored
Returns:
a new Function3
See Also:
Lambda


Copyright © 2011-2012 StaccatoCommons. All Rights Reserved.