|
|||||||||
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<? extends X> iterable)
applies Function to an Iterable |
|
java.util.Iterator<Y> |
apply(java.util.Iterator<? extends X> iterator)
applies Function to an Iterator |
|
java.util.List<Y> |
apply(java.util.List<? extends X> domain)
applies Function to a List |
|
abstract Y |
apply(X x)
the only method you should implement |
|
|
compose(Function<W,? extends 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,? extends Y> f,
Function<? super Y,? extends Z> g)
Returns a compostion f.g : X->Z of two functions, f: X->Y and g: Y->Z. |
|
static
|
forMap(java.util.Map<? super X,Y> map,
Y defaultValue)
Returns a function defied by a map and a default value |
|
static
|
forMap(java.util.Map<X,Y> map)
turns a Map into a Function |
|
static
|
function(java.util.Map<? super X,Y> map,
Y defaultValue)
Deprecated. use forMap instead. |
|
static
|
function(java.util.Map<X,Y> map)
Deprecated. use forMap instead |
|
static
|
id()
|
|
java.util.Map<X,Y> |
toMap(java.util.Collection<? extends X> keys)
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<? extends X> keys)
Restricts this function to a specified Set, returning a map with keys from the 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<? extends X> keys)
keys
- Set<X> keys
public java.util.Map<X,Y> toMap(java.util.Collection<? extends X> keys)
keys
- Collection<X> keys
public static <X,Y> Function<X,Y> forMap(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)
map
- Map<X,Y> source map
public static <X,Y> Function<X,Y> forMap(java.util.Map<? super X,Y> map, Y defaultValue)
map
- Map<X,Y>defaultValue
- Y
public static <X,Y> Function<X,Y> function(java.util.Map<? super X,Y> map, Y defaultValue)
map
- Map<X,Y>defaultValue
- Y
public java.util.List<Y> apply(java.util.List<? extends X> domain)
domain
- List
public java.util.Iterator<Y> apply(java.util.Iterator<? extends 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<? extends X> iterable)
iterable
- Iterable
public <W> Function<W,Y> compose(Function<W,? extends X> g)
g
- Function<W,X>
public static <X,Y,Z> Function<X,Z> compose(Function<X,? extends Y> f, Function<? super Y,? extends Z> g)
f
- Function<X,Y>g
- Function<Y,Z>
public static <X> Function<X,X> id()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |