org.op4j.functions
Class FnFunc

Object
  extended by org.op4j.functions.FnFunc

public final class FnFunc
extends Object

Since:
1.0
Author:
Daniel Fernández

Method Summary
static
<X,Y,Z> Function<X,Z>
chain(IFunction<X,Y> fn1, IFunction<? super Y,Z> fn2)
           Chains two functions together.
static
<T> Function<T,T>
ifFalseThen(org.javaruntype.type.Type<T> targetType, IFunction<? super T,Boolean> condition, IFunction<? super T,? extends T> thenFunction)
           Builds a function that will execute the specified function thenFunction only if the result of executing condition on the target object is false.
static
<T,R> Function<T,R>
ifFalseThenElse(org.javaruntype.type.Type<T> targetType, IFunction<? super T,Boolean> condition, IFunction<? super T,R> thenFunction, IFunction<? super T,R> elseFunction)
           Builds a function that will execute the specified function thenFunction only if the result of executing condition on the target object is false, and will execute the specified function elseFunction otherwise.
static
<T> Function<T,T>
ifNotNullAndFalseThen(org.javaruntype.type.Type<T> targetType, IFunction<? super T,Boolean> condition, IFunction<? super T,? extends T> thenFunction)
           Builds a function that will execute the specified function thenFunction only if the target object is not null and the result of executing condition on it is false.
static
<T,R> Function<T,R>
ifNotNullAndFalseThenElse(org.javaruntype.type.Type<T> targetType, IFunction<? super T,Boolean> condition, IFunction<? super T,R> thenFunction, IFunction<? super T,R> elseFunction)
           Builds a function that will execute the specified function thenFunction only if the target object is not null and the result of executing condition on the target object is false, and will execute the specified function elseFunction otherwise.
static
<T> Function<T,T>
ifNotNullAndTrueThen(org.javaruntype.type.Type<T> targetType, IFunction<? super T,Boolean> condition, IFunction<? super T,? extends T> thenFunction)
           Builds a function that will execute the specified function thenFunction only if the target object is not null and the result of executing condition on it is true.
static
<T,R> Function<T,R>
ifNotNullAndTrueThenElse(org.javaruntype.type.Type<T> targetType, IFunction<? super T,Boolean> condition, IFunction<? super T,R> thenFunction, IFunction<? super T,R> elseFunction)
           Builds a function that will execute the specified function thenFunction only if the target object is not null and the result of executing condition on the target object is true, and will execute the specified function elseFunction otherwise.
static
<T> Function<T,T>
ifNotNullThen(org.javaruntype.type.Type<T> targetType, IFunction<? super T,? extends T> thenFunction)
           Builds a function that will execute the specified function thenFunction only if the target object is not null.
static
<T,R> Function<T,R>
ifNotNullThenElse(org.javaruntype.type.Type<T> targetType, IFunction<? super T,R> thenFunction, IFunction<? super T,R> elseFunction)
           Builds a function that will execute the specified function thenFunction only if the target object is not null, and will execute the specified function elseFunction otherwise.
static
<T> Function<T,T>
ifNullOrFalseThen(org.javaruntype.type.Type<T> targetType, IFunction<? super T,Boolean> condition, IFunction<? super T,? extends T> thenFunction)
           Builds a function that will execute the specified function thenFunction only if the target object is null or the result of executing condition on it is false.
static
<T,R> Function<T,R>
ifNullOrFalseThenElse(org.javaruntype.type.Type<T> targetType, IFunction<? super T,Boolean> condition, IFunction<? super T,R> thenFunction, IFunction<? super T,R> elseFunction)
           Builds a function that will execute the specified function thenFunction only if the target object is null or the result of executing condition on the target object is false, and will execute the specified function elseFunction otherwise.
static
<T> Function<T,T>
ifNullOrTrueThen(org.javaruntype.type.Type<T> targetType, IFunction<? super T,Boolean> condition, IFunction<? super T,? extends T> thenFunction)
           Builds a function that will execute the specified function thenFunction only if the target object is null or the result of executing condition on it is true.
static
<T,R> Function<T,R>
ifNullOrTrueThenElse(org.javaruntype.type.Type<T> targetType, IFunction<? super T,Boolean> condition, IFunction<? super T,R> thenFunction, IFunction<? super T,R> elseFunction)
           Builds a function that will execute the specified function thenFunction only if the target object is null or the result of executing condition on the target object is true, and will execute the specified function elseFunction otherwise.
static
<T> Function<T,T>
ifNullThen(org.javaruntype.type.Type<T> targetType, IFunction<? super T,? extends T> thenFunction)
           Builds a function that will execute the specified function thenFunction only if the target object is null.
static
<T,R> Function<T,R>
ifNullThenElse(org.javaruntype.type.Type<T> targetType, IFunction<? super T,R> thenFunction, IFunction<? super T,R> elseFunction)
           Builds a function that will execute the specified function thenFunction only if the target object is null, and will execute the specified function elseFunction otherwise.
static
<T> Function<T,T>
ifTrueThen(org.javaruntype.type.Type<T> targetType, IFunction<? super T,Boolean> condition, IFunction<? super T,? extends T> thenFunction)
           Builds a function that will execute the specified function thenFunction only if the result of executing condition on the target object is true.
static
<T,R> Function<T,R>
ifTrueThenElse(org.javaruntype.type.Type<T> targetType, IFunction<? super T,Boolean> condition, IFunction<? super T,R> thenFunction, IFunction<? super T,R> elseFunction)
           Builds a function that will execute the specified function thenFunction only if the result of executing condition on the target object is true, and will execute the specified function elseFunction otherwise.
static
<T> Function<T,T>
whileFalse(IFunction<? super T,Boolean> condition, IFunction<? super T,T> function)
           Executes the specified function iteratively (first on the target, then on the result of the previous iteration) while the result of executing the condition function on the target object (or the result of the previous function iteration) is false.
static
<T> Function<T,T>
whileTrue(IFunction<? super T,Boolean> condition, IFunction<? super T,T> function)
           Executes the specified function iteratively (first on the target, then on the result of the previous iteration) while the result of executing the condition function on the target object (or the result of the previous function iteration) is true.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

chain

public static final <X,Y,Z> Function<X,Z> chain(IFunction<X,Y> fn1,
                                                IFunction<? super Y,Z> fn2)

Chains two functions together. The returned function executes the specified functions in sequence, being fn2 executed on the results of fn1.

Parameters:
fn1 - the first function to be executed
fn2 - the second function to be executed
Returns:
a function that executes first fn1, then fn2 on the results of fn1.

ifTrueThen

public static final <T> Function<T,T> ifTrueThen(org.javaruntype.type.Type<T> targetType,
                                                 IFunction<? super T,Boolean> condition,
                                                 IFunction<? super T,? extends T> thenFunction)

Builds a function that will execute the specified function thenFunction only if the result of executing condition on the target object is true.

The built function cannot change the return type (receives T and returns T) because the thenFunction could remain unexecuted, and so the type returned by thenFunction must be the same as the type required as input, in order to keep consistency.

Parameters:
targetType - the target type
condition - the condition to be executed on the target object
thenFunction - the function to be executed on the target object if condition is true
Returns:
a function that executes the "thenFunction" if "condition" is true.

ifTrueThenElse

public static final <T,R> Function<T,R> ifTrueThenElse(org.javaruntype.type.Type<T> targetType,
                                                       IFunction<? super T,Boolean> condition,
                                                       IFunction<? super T,R> thenFunction,
                                                       IFunction<? super T,R> elseFunction)

Builds a function that will execute the specified function thenFunction only if the result of executing condition on the target object is true, and will execute the specified function elseFunction otherwise.

The built function can effectively change the target type (receive T and return R) if both thenFunction and elseFunction return the same type, and this is different than the target type T.

Parameters:
targetType - the target type
condition - the condition to be executed on the target object
thenFunction - the function to be executed on the target object if condition is true
elseFunction - the function to be executed on the target object otherwise
Returns:
a function that executes the "thenFunction" if "condition" is true and "elseFunction" otherwise.

ifFalseThen

public static final <T> Function<T,T> ifFalseThen(org.javaruntype.type.Type<T> targetType,
                                                  IFunction<? super T,Boolean> condition,
                                                  IFunction<? super T,? extends T> thenFunction)

Builds a function that will execute the specified function thenFunction only if the result of executing condition on the target object is false.

The built function cannot change the return type (receives T and returns T) because the thenFunction could remain unexecuted, and so the type returned by thenFunction must be the same as the type required as input, in order to keep consistency.

Parameters:
targetType - the target type
condition - the condition to be executed on the target object
thenFunction - the function to be executed on the target object if condition is false
Returns:
a function that executes the "thenFunction" if "condition" is false.

ifFalseThenElse

public static final <T,R> Function<T,R> ifFalseThenElse(org.javaruntype.type.Type<T> targetType,
                                                        IFunction<? super T,Boolean> condition,
                                                        IFunction<? super T,R> thenFunction,
                                                        IFunction<? super T,R> elseFunction)

Builds a function that will execute the specified function thenFunction only if the result of executing condition on the target object is false, and will execute the specified function elseFunction otherwise.

The built function can effectively change the target type (receive T and return R) if both thenFunction and elseFunction return the same type, and this is different than the target type T.

Parameters:
targetType - the target type
condition - the condition to be executed on the target object
thenFunction - the function to be executed on the target object if condition is false
elseFunction - the function to be executed on the target object otherwise
Returns:
a function that executes the "thenFunction" if "condition" is false and "elseFunction" otherwise.

ifNullThen

public static final <T> Function<T,T> ifNullThen(org.javaruntype.type.Type<T> targetType,
                                                 IFunction<? super T,? extends T> thenFunction)

Builds a function that will execute the specified function thenFunction only if the target object is null.

The built function cannot change the return type (receives T and returns T) because the thenFunction could remain unexecuted, and so the type returned by thenFunction must be the same as the type required as input, in order to keep consistency.

Parameters:
targetType - the target type.
thenFunction - the function to be executed on the target object if it is null.
Returns:
a function that executes the "thenFunction" if the target object is null.

ifNullThenElse

public static final <T,R> Function<T,R> ifNullThenElse(org.javaruntype.type.Type<T> targetType,
                                                       IFunction<? super T,R> thenFunction,
                                                       IFunction<? super T,R> elseFunction)

Builds a function that will execute the specified function thenFunction only if the target object is null, and will execute the specified function elseFunction otherwise.

The built function can effectively change the target type (receive T and return R) if both thenFunction and elseFunction return the same type, and this is different than the target type T.

Parameters:
targetType - the target type
thenFunction - the function to be executed on the target object is null
elseFunction - the function to be executed on the target object otherwise
Returns:
a function that executes the "thenFunction" if the target object is null and "elseFunction" otherwise.

ifNotNullThen

public static final <T> Function<T,T> ifNotNullThen(org.javaruntype.type.Type<T> targetType,
                                                    IFunction<? super T,? extends T> thenFunction)

Builds a function that will execute the specified function thenFunction only if the target object is not null.

The built function cannot change the return type (receives T and returns T) because the thenFunction could remain unexecuted, and so the type returned by thenFunction must be the same as the type required as input, in order to keep consistency.

Parameters:
targetType - the target type.
thenFunction - the function to be executed on the target object if it is not null.
Returns:
a function that executes the "thenFunction" if the target object is not null.

ifNotNullThenElse

public static final <T,R> Function<T,R> ifNotNullThenElse(org.javaruntype.type.Type<T> targetType,
                                                          IFunction<? super T,R> thenFunction,
                                                          IFunction<? super T,R> elseFunction)

Builds a function that will execute the specified function thenFunction only if the target object is not null, and will execute the specified function elseFunction otherwise.

The built function can effectively change the target type (receive T and return R) if both thenFunction and elseFunction return the same type, and this is different than the target type T.

Parameters:
targetType - the target type
thenFunction - the function to be executed on the target object is not null
elseFunction - the function to be executed on the target object otherwise
Returns:
a function that executes the "thenFunction" if the target object is not null and "elseFunction" otherwise.

ifNullOrTrueThen

public static final <T> Function<T,T> ifNullOrTrueThen(org.javaruntype.type.Type<T> targetType,
                                                       IFunction<? super T,Boolean> condition,
                                                       IFunction<? super T,? extends T> thenFunction)

Builds a function that will execute the specified function thenFunction only if the target object is null or the result of executing condition on it is true.

The built function cannot change the return type (receives T and returns T) because the thenFunction could remain unexecuted, and so the type returned by thenFunction must be the same as the type required as input, in order to keep consistency.

Parameters:
targetType - the target type
condition - the condition to be executed on the target object
thenFunction - the function to be executed on the target object if target is null or the result of executing condition on it is true
Returns:
a function that executes the "thenFunction" if target is null or "condition" is true.

ifNullOrTrueThenElse

public static final <T,R> Function<T,R> ifNullOrTrueThenElse(org.javaruntype.type.Type<T> targetType,
                                                             IFunction<? super T,Boolean> condition,
                                                             IFunction<? super T,R> thenFunction,
                                                             IFunction<? super T,R> elseFunction)

Builds a function that will execute the specified function thenFunction only if the target object is null or the result of executing condition on the target object is true, and will execute the specified function elseFunction otherwise.

The built function can effectively change the target type (receive T and return R) if both thenFunction and elseFunction return the same type, and this is different than the target type T.

Parameters:
targetType - the target type
condition - the condition to be executed on the target object
thenFunction - the function to be executed on the target object if target is null or the result of executing condition on it is true
elseFunction - the function to be executed on the target object otherwise
Returns:
a function that executes the "thenFunction" if target is null or "condition" is true, and "elseFunction" otherwise.

ifNullOrFalseThen

public static final <T> Function<T,T> ifNullOrFalseThen(org.javaruntype.type.Type<T> targetType,
                                                        IFunction<? super T,Boolean> condition,
                                                        IFunction<? super T,? extends T> thenFunction)

Builds a function that will execute the specified function thenFunction only if the target object is null or the result of executing condition on it is false.

The built function cannot change the return type (receives T and returns T) because the thenFunction could remain unexecuted, and so the type returned by thenFunction must be the same as the type required as input, in order to keep consistency.

Parameters:
targetType - the target type
condition - the condition to be executed on the target object
thenFunction - the function to be executed on the target object if target is null or the result of executing condition on it is false
Returns:
a function that executes the "thenFunction" if target is null or "condition" is false.

ifNullOrFalseThenElse

public static final <T,R> Function<T,R> ifNullOrFalseThenElse(org.javaruntype.type.Type<T> targetType,
                                                              IFunction<? super T,Boolean> condition,
                                                              IFunction<? super T,R> thenFunction,
                                                              IFunction<? super T,R> elseFunction)

Builds a function that will execute the specified function thenFunction only if the target object is null or the result of executing condition on the target object is false, and will execute the specified function elseFunction otherwise.

The built function can effectively change the target type (receive T and return R) if both thenFunction and elseFunction return the same type, and this is different than the target type T.

Parameters:
targetType - the target type
condition - the condition to be executed on the target object
thenFunction - the function to be executed on the target object if target is null or the result of executing condition on it is false
elseFunction - the function to be executed on the target object otherwise
Returns:
a function that executes the "thenFunction" if target is null or "condition" is false, and "elseFunction" otherwise.

ifNotNullAndTrueThen

public static final <T> Function<T,T> ifNotNullAndTrueThen(org.javaruntype.type.Type<T> targetType,
                                                           IFunction<? super T,Boolean> condition,
                                                           IFunction<? super T,? extends T> thenFunction)

Builds a function that will execute the specified function thenFunction only if the target object is not null and the result of executing condition on it is true.

The built function cannot change the return type (receives T and returns T) because the thenFunction could remain unexecuted, and so the type returned by thenFunction must be the same as the type required as input, in order to keep consistency.

Parameters:
targetType - the target type
condition - the condition to be executed on the target object
thenFunction - the function to be executed on the target object if target is not null and the result of executing condition on it is true
Returns:
a function that executes the "thenFunction" if target is not null and "condition" is true.

ifNotNullAndTrueThenElse

public static final <T,R> Function<T,R> ifNotNullAndTrueThenElse(org.javaruntype.type.Type<T> targetType,
                                                                 IFunction<? super T,Boolean> condition,
                                                                 IFunction<? super T,R> thenFunction,
                                                                 IFunction<? super T,R> elseFunction)

Builds a function that will execute the specified function thenFunction only if the target object is not null and the result of executing condition on the target object is true, and will execute the specified function elseFunction otherwise.

The built function can effectively change the target type (receive T and return R) if both thenFunction and elseFunction return the same type, and this is different than the target type T.

Parameters:
targetType - the target type
condition - the condition to be executed on the target object
thenFunction - the function to be executed on the target object if target is not null and the result of executing condition on it is true
elseFunction - the function to be executed on the target object otherwise
Returns:
a function that executes the "thenFunction" if target is not null and "condition" is true, and "elseFunction" otherwise.

ifNotNullAndFalseThen

public static final <T> Function<T,T> ifNotNullAndFalseThen(org.javaruntype.type.Type<T> targetType,
                                                            IFunction<? super T,Boolean> condition,
                                                            IFunction<? super T,? extends T> thenFunction)

Builds a function that will execute the specified function thenFunction only if the target object is not null and the result of executing condition on it is false.

The built function cannot change the return type (receives T and returns T) because the thenFunction could remain unexecuted, and so the type returned by thenFunction must be the same as the type required as input, in order to keep consistency.

Parameters:
targetType - the target type
condition - the condition to be executed on the target object
thenFunction - the function to be executed on the target object if target is not null and the result of executing condition on it is false
Returns:
a function that executes the "thenFunction" if target is not null and "condition" is false.

ifNotNullAndFalseThenElse

public static final <T,R> Function<T,R> ifNotNullAndFalseThenElse(org.javaruntype.type.Type<T> targetType,
                                                                  IFunction<? super T,Boolean> condition,
                                                                  IFunction<? super T,R> thenFunction,
                                                                  IFunction<? super T,R> elseFunction)

Builds a function that will execute the specified function thenFunction only if the target object is not null and the result of executing condition on the target object is false, and will execute the specified function elseFunction otherwise.

The built function can effectively change the target type (receive T and return R) if both thenFunction and elseFunction return the same type, and this is different than the target type T.

Parameters:
targetType - the target type
condition - the condition to be executed on the target object
thenFunction - the function to be executed on the target object if target is not null and the result of executing condition on it is false
elseFunction - the function to be executed on the target object otherwise
Returns:
a function that executes the "thenFunction" if target is not null and "condition" is false, and "elseFunction" otherwise.

whileTrue

public static final <T> Function<T,T> whileTrue(IFunction<? super T,Boolean> condition,
                                                IFunction<? super T,T> function)

Executes the specified function iteratively (first on the target, then on the result of the previous iteration) while the result of executing the condition function on the target object (or the result of the previous function iteration) is true.

Parameters:
condition - the condition function to be applied
function - the function to be executed iteratively
Returns:
a function executing the specified function iteratively while the condition is true.

whileFalse

public static final <T> Function<T,T> whileFalse(IFunction<? super T,Boolean> condition,
                                                 IFunction<? super T,T> function)

Executes the specified function iteratively (first on the target, then on the result of the previous iteration) while the result of executing the condition function on the target object (or the result of the previous function iteration) is false.

Parameters:
condition - the condition function to be applied
function - the function to be executed iteratively
Returns:
a function executing the specified function iteratively while the condition is false.


Copyright © 2012 The OP4J team. All Rights Reserved.