|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.myjavatools.lib.foundation.Function<X,Y>
public abstract class Function<X,Y>
Function is an abstract class that represents the mathematical notion of function: X -> Y. To implement a function, you need to define method apply(): Y y = function.apply(X x).
Filter,
Maps,
Map| Constructor Summary | |
|---|---|
Function()
|
|
| Method Summary | ||
|---|---|---|
java.lang.Iterable<Y> |
apply(java.lang.Iterable<X> iterable)
applies Function to an Iterable |
|
java.util.Iterator<Y> |
apply(java.util.Iterator<X> iterator)
applies Function to an Iterator |
|
java.util.List<Y> |
apply(java.util.List<X> domain)
applies Function to a List |
|
abstract Y |
apply(X x)
the only method you should implement |
|
|
compose(Function<W,X> g)
Returns a composition f.g : W->Y of two functions, g:W->X and f(which is this Function): X->Y. |
|
static
|
compose(Function<X,Y> f,
Function<Y,Z> g)
Returns a compostion f.g : X->Z of two functions, f: X->Y and g: Y->Z. |
|
static
|
function(java.util.Map<X,Y> map)
turns a Map into a Function |
|
static
|
function(java.util.Map<X,Y> map,
Y defaultValue)
Returns a function defied by a map and a default value |
|
java.util.Map<X,Y> |
toMap(java.util.Collection<X> x)
Restricts this function to a specified Collection, returning a map on the set of collection entries |
|
java.util.Map<X,Y> |
toMap(java.util.Set<X> x)
Restricts this function to a specified X Set, returning a Map on that set |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Function()
| Method Detail |
|---|
public abstract Y apply(X x)
x - X the function parameter
public java.util.Map<X,Y> toMap(java.util.Set<X> x)
x - Set<X> the set of map keys
public java.util.Map<X,Y> toMap(java.util.Collection<X> x)
x - Collection<X> keys
public static <X,Y> Function<X,Y> function(java.util.Map<X,Y> map)
map - Map<X,Y> source map
public static <X,Y> Function<X,Y> function(java.util.Map<X,Y> map,
Y defaultValue)
map - Map<X,Y>defaultValue - Y
public java.util.List<Y> apply(java.util.List<X> domain)
domain - List
public java.util.Iterator<Y> apply(java.util.Iterator<X> iterator)
iterator - Iterator
Example:
new Function<String, Integer>() {
Integer apply(String s) { return s.length(); } }.
apply(
Arrays.asList(new String[] {"One", "Two", "Three"}).iterator());
returns an iterator returning 3, 3, 5.public java.lang.Iterable<Y> apply(java.lang.Iterable<X> iterable)
iterable - Iterable
public <W> Function<W,Y> compose(Function<W,X> g)
g - Function<W,X>
public static <X,Y,Z> Function<X,Z> compose(Function<X,Y> f,
Function<Y,Z> g)
f - Function<X,Y>g - Function<Y,Z>
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||