|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.staccatocommons.lambda.Lambda
public final class Lambda
An utility class for accessing in a shared, thread safe LambdaFactory
, or creating standalone LambdaFactorys
Lambda and LambdaFactory a DSL for instantiating simple
Functions and Predicates. There are two manners of using
those classes:
Lambda,
and combine $(Class) with lambda(Object) and variants, in
the form lambdaVariant($(ArgumentType).message(args...)) . For
example:
lambda($(Collection.class).isEmpty());This creates a new
Predicate that takes a Collection argument
and answers if it is empty. It is equivalent to the more verbose:
new Predicate<Collection>() {
public boolean eval(Collection arg) {
return arg.isEmpty();
}
};
Although this syntax is quite convenient, accessing the shared
LambdaFactory - hidden by the static-imports - needs a thread local
variable to make it thread safe, which may be seen in some contexts like
resources waste.
LambdaFactory l = Lambda.factory(); l.lambda(l.$(Collection.class).isEmpty());Local factories must be declared as local variables.
LambdaFactory| Field Summary | |
|---|---|
static Object |
_
Equivalent to _(Object.class) |
| Constructor Summary | |
|---|---|
Lambda()
|
|
| Method Summary | ||
|---|---|---|
static
|
_(Class<A> clazz)
Answers a placeholder for lambdas arguments with arity > 1. |
|
static
|
$(Class<A> clazz)
Stubs a type for creating a lambda. |
|
static LambdaFactory |
factory()
Answers a new LambdaFactory that is capable of stubbing interfaces
and non-final classes |
|
static
|
lambda(B returnType)
Answers a Function that when applied sends to its argument the
message previously sent to the last stubbed type. |
|
static
|
lambda(boolean returnType)
Answers a Predicate that when evaluated sends to its argument the
message previously sent to the last stubbed type. |
|
static
|
lambda2(boolean returnType)
Answers a Predicate1 that when evaluated sends to its first
argument the message previously sent to the last stubbed type, passing its
second argument as the first message argument. |
|
static
|
lambda2(C returnType)
Answers a Function2 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. |
|
static
|
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. |
|
static net.sf.staccatocommons.defs.predicate.Predicate |
ulambda(boolean returnType)
Same that lambda(boolean), but discarding type parameters |
|
static net.sf.staccatocommons.defs.function.Function |
ulambda(Object returnType)
Same that lambda(Object), but discarding type parameters |
|
static net.sf.staccatocommons.defs.predicate.Predicate2 |
ulambda2(boolean returnType)
Same that lambda2(boolean), but discarding type parameters |
|
static net.sf.staccatocommons.defs.function.Function2 |
ulambda2(Object returnType)
Same that lambda2(Object), but discarding type parameters |
|
static net.sf.staccatocommons.defs.function.Function3 |
ulambda3(Object returnType)
Same that lambda3(Object), but discarding type parameters |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Object _
| Constructor Detail |
|---|
public Lambda()
| Method Detail |
|---|
public static <A> A $(Class<A> clazz)
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
A - clazz - the type to stub
LambdaFactory.$(java.lang.Class)public static <A,B> net.sf.staccatocommons.defs.function.Function<A,B> lambda(B returnType)
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
returnType - meaningless, this argument is simply ignored
FunctionLambdaFactory.lambda(java.lang.Object)public static net.sf.staccatocommons.defs.function.Function ulambda(Object returnType)
lambda(Object), but discarding type parameters
public static <A> net.sf.staccatocommons.defs.predicate.Predicate<A> lambda(boolean returnType)
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
returnType - meaningless, this argument is simply ignored
PredicateLambda,
LambdaFactory.lambda(boolean)public static net.sf.staccatocommons.defs.predicate.Predicate ulambda(boolean returnType)
lambda(boolean), but discarding type parameters
public static <A,B,C> net.sf.staccatocommons.defs.function.Function2<A,B,C> lambda2(C returnType)
Function2 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. Refer to the use cases described in
Lambda
returnType - meaningless, this argument is simply ignored
Function2LambdaFactory.lambda2(java.lang.Object)public static net.sf.staccatocommons.defs.function.Function2 ulambda2(Object returnType)
lambda2(Object), but discarding type parameters
public static <A,B> net.sf.staccatocommons.defs.predicate.Predicate2<A,B> lambda2(boolean returnType)
Predicate1 that when evaluated sends to its first
argument the message previously sent to the last stubbed type, passing its
second argument as the first message argument. Refer to the use cases
described in Lambda
returnType - meaningless, this argument is simply ignored
PredicateLambda,
LambdaFactory.lambda2(boolean)public static net.sf.staccatocommons.defs.predicate.Predicate2 ulambda2(boolean returnType)
lambda2(boolean), but discarding type parameters
public static <A,B,C,D> net.sf.staccatocommons.defs.function.Function3<A,B,C,D> lambda3(D returnType)
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
returnType - meaningless, this argument is simply ignored
Function3LambdaFactory.lambda3(java.lang.Object)public static net.sf.staccatocommons.defs.function.Function3 ulambda3(Object returnType)
lambda3(Object), but discarding type parameters
public static LambdaFactory factory()
LambdaFactory that is capable of stubbing interfaces
and non-final classes
LambdaFactorypublic static <A> A _(Class<A> clazz)
A - clazz -
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||