net.sf.eos.util
Class Compositions

java.lang.Object
  extended by net.sf.eos.util.Compositions

@Experimental
public class Compositions
extends Object

Defines some useful compositions for handling with Functions, Predicates and Suppliers.

Each composition follows the rule of a from or source entity, propagating its result value to a to or target entity.

Author:
Sascha Kohlmann

Method Summary
static
<F,I,T> Function<F,T>
compose(Function<? super F,? extends I> from, Function<? super I,? extends T> to)
          Returns the composition of two functions.
static
<F,T> Predicate<F>
compose(Function<? super F,? extends T> fromFunction, Predicate<T> toPredicate)
          Returns a composition of a from Function and an evaluating to Predicate.
static
<F,T> Supplier<T>
compose(Supplier<? extends F> fromSupplier, Function<F,T> toFunction)
          Returns a composition of a from Supplier and an applied to Function.
static
<F,T> Function<F,T>
composeRule(Predicate<? super F> decider, Function<? super F,? extends T> trueFunction, Function<? super F,? extends T> falseFunction)
          Composes a rule.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

compose

public static final <F,I,T> Function<F,T> compose(Function<? super F,? extends I> from,
                                                  Function<? super I,? extends T> to)
Returns the composition of two functions. For f: F→I and g: I→T, composition is defined as the function h such that h(x) == g(f(x)) for each x.

The usage interface is designed as a from function which propagates its result to the to function.

Type Parameters:
F - the from or source type
I - the intermediate type
T - the to or target type
Parameters:
from - the from or source function
to - the to or target function
Throws:
IllegalArgumentException - if one parameter is null
Since:
0.1.0

compose

public static final <F,T> Predicate<F> compose(Function<? super F,? extends T> fromFunction,
                                               Predicate<T> toPredicate)
Returns a composition of a from Function and an evaluating to Predicate. The predicate retrieves the value from the function.

The usage interface is designed as a from function which propagates its result to the to predicate.

Type Parameters:
F - the from or source type
T - the to or target type
Parameters:
fromFunction - the from or source function
toPredicate - the to or target predicate
Returns:
a predicate
Throws:
IllegalArgumentException - if one parameter is null
Since:
0.7.0

compose

public static final <F,T> Supplier<T> compose(Supplier<? extends F> fromSupplier,
                                              Function<F,T> toFunction)
Returns a composition of a from Supplier and an applied to Function. The function retrieves the value from the supplier.

The usage interface is designed as a from supplier which propagates its result to the to function.

Type Parameters:
F - the from or source type
T - the to or target type
Parameters:
fromSupplier - the from or source supplier
toFunction - the to or target function
Returns:
a supplier with the value from function
Throws:
IllegalArgumentException - if one parameter is null
Since:
0.7.0

composeRule

public static final <F,T> Function<F,T> composeRule(Predicate<? super F> decider,
                                                    Function<? super F,? extends T> trueFunction,
                                                    Function<? super F,? extends T> falseFunction)
Composes a rule. A rule contains a predicate as decision maker either to call the trueFunction or the falseFunction. The returning function calls the trueFunction if predicate returns true. Otherwise the falseFunction will call.

Type Parameters:
F - the input type of the predicate and the functions
T - the output type of the applyied functions
Parameters:
decider - the decision maker
trueFunction - apply if the decision maker returns true
falseFunction - apply if the decision maker returns false
Returns:
a ruling function
Since:
0.8.1


Copyright © 2008. All Rights Reserved.