|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectariba.util.core.Function<K>
public abstract class Function<K>
Generic class that represents a function returning a type K
.
final Function<String> substring = new Function<String>() { public String evaluate (Object... arguments) { String string = (String)arguments[0]; return string.length() > 2 ? string.substring(0,3) : null; } }; List<String> someBigListOfStrings = ...; Map<String,List<String>> result = substring.split(someBigListOfStrings);
result
will hold a map mapping the first 3 characters to all the
strings in the orginal list that begin with the same three characters.
Feel free to add more methods to this class. We could use a
int find(Collection<V> list, K k)
method returning the index of the
V
in the list that for which the application of the Function
yields k
. Similarly we could use a collectWhere()
.
Nested Class Summary | |
---|---|
static class |
Function.MethodFunction<T>
Convenience nested class that adapts a Method into a
Function |
Field Summary | |
---|---|
static Function |
Identity
|
Constructor Summary | |
---|---|
Function()
|
Method Summary | ||
---|---|---|
|
collect(java.lang.Iterable<V> values)
Iterates over values applying this to
each instance of V and adding the results of the evaluations to
the returned list. |
|
|
collect(java.lang.Iterable<V> values,
boolean includeNulls)
Iterates over values applying this to
each instance of V and adding the results of the evaluations to
the returned list. |
|
|
collectInto(java.lang.Iterable<V> values,
java.util.Collection<K> collector,
boolean includeNulls)
Iterates over values applying this to
each instance of V and adding tje results of the evaulations to
collector |
|
abstract K |
evaluate(java.lang.Object... arguments)
Evaluates the supplied arguments returning an instance of
type K . |
|
boolean |
hasSameValue(java.lang.Iterable elements)
Returns true if each of the elements in elements
has the same value according to this function. |
|
static
|
identity()
|
|
static
|
make(java.lang.Class cls,
java.lang.String methodName,
java.lang.Class... argumentTypes)
Convenience function that returns a new Function based on
the supplied Method . |
|
static
|
make(java.lang.reflect.Method method)
Convenience function that returns a new Function based on
the supplied Method . |
|
|
map(java.lang.Iterable<V> values)
Iterates over values applying this to
each instance of V and adding the mapping to the returned map. |
|
|
map(java.lang.Iterable<V> values,
boolean includeNulls)
Iterates over values applying this to
each instance of V and adding the mapping to the returned map. |
|
|
mapInto(java.lang.Iterable<V> values,
java.util.Map<V,K> collector,
boolean includeNulls)
Iterates over values applying this to
each instance of V and adding the mapping to collector . |
|
|
reverseMapInto(java.lang.Iterable<V> values,
java.util.Map<K,V> collector,
boolean includeNulls)
Iterates over values applying this to
each instance of V and adding the reverse mapping to collector . |
|
|
reverseMapInto(V[] values,
java.util.Map<K,V> collector,
boolean includeNulls)
Iterates over values applying this to
each instance of V and adding the reverse mapping to collector . |
|
|
split(java.lang.Iterable<V> collection)
Efficiently, splits the supplied collection of a value type
V returning a map which is a partition of the collection using
this function. |
|
|
splitInto(java.lang.Iterable<V> collection,
java.util.Map<K,java.util.List<V>> result)
Efficiently, splits the supplied collection of a value type
V returning a map which is a partition of the collection using
this function. |
|
|
splitInto(java.lang.Iterable<V> collection,
java.util.Map<K,java.util.List<V>> result,
boolean includeNulls)
Efficiently, splits the supplied collection of a value type
V returning a map which is a partition of the collection using
this function. |
|
|
splitInto(java.lang.Iterable<V> collection,
java.util.Map<K,W> result,
Aggregator<W,V> aggregator,
boolean includeNulls)
Efficiently, splits the supplied collection of a value type
V returning a map which is a partition of the collection using
this function. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static Function Identity
Constructor Detail |
---|
public Function()
Method Detail |
---|
public abstract K evaluate(java.lang.Object... arguments) throws EvaluationException
arguments
returning an instance of
type K
.
arguments
- the arguments to be evaulated
K
EvaluationException
public boolean hasSameValue(java.lang.Iterable elements)
true
if each of the elements in elements
has the same value according to this function.
public <V,W> void splitInto(java.lang.Iterable<V> collection, java.util.Map<K,W> result, Aggregator<W,V> aggregator, boolean includeNulls)
collection
of a value type
V
returning a map which is a partition of the collection using
this function.
Using the aggregator function when merging the value to the map.
Specifically, this method splits collection
into sub-lists
each of which has the same value when evaluated by this function.
public <V> void splitInto(java.lang.Iterable<V> collection, java.util.Map<K,java.util.List<V>> result, boolean includeNulls)
collection
of a value type
V
returning a map which is a partition of the collection using
this function.
Specifically, this method splits collection
into sub-lists
each of which has the same value when evaluated by this function.
public <V> void splitInto(java.lang.Iterable<V> collection, java.util.Map<K,java.util.List<V>> result)
collection
of a value type
V
returning a map which is a partition of the collection using
this function.
Specifically, this method splits collection
into sub-lists
each of which has the same value when evaluated by this function.
public <V> java.util.Map<K,java.util.List<V>> split(java.lang.Iterable<V> collection)
collection
of a value type
V
returning a map which is a partition of the collection using
this function.
Specifically, this method splits collection
into sub-lists
each of which has the same value when evaluated by this function.
public <V> void mapInto(java.lang.Iterable<V> values, java.util.Map<V,K> collector, boolean includeNulls)
values
applying this
to
each instance of V
and adding the mapping to collector
.
values
- the collection of valuescollector
- the resulting mapincludeNulls
- whether or not null
evaluations should be mappedpublic final <V> java.util.Map<V,K> map(java.lang.Iterable<V> values, boolean includeNulls)
values
applying this
to
each instance of V
and adding the mapping to the returned map.
values
- the collection of valuesincludeNulls
- whether or not null
evaluations should be mapped
public final <V> java.util.Map<V,K> map(java.lang.Iterable<V> values)
values
applying this
to
each instance of V
and adding the mapping to the returned map.
values
- the collection of values
public final <V> void reverseMapInto(java.lang.Iterable<V> values, java.util.Map<K,V> collector, boolean includeNulls)
values
applying this
to
each instance of V
and adding the reverse mapping to collector
.
values
- the collection of valuescollector
- the resulting mapincludeNulls
- whether or not null
evaluations should be mappedpublic final <V> void reverseMapInto(V[] values, java.util.Map<K,V> collector, boolean includeNulls)
values
applying this
to
each instance of V
and adding the reverse mapping to collector
.
values
- the collection of valuescollector
- the resulting mapincludeNulls
- whether or not null
evaluations should be mappedpublic final <V> void collectInto(java.lang.Iterable<V> values, java.util.Collection<K> collector, boolean includeNulls)
values
applying this
to
each instance of V
and adding tje results of the evaulations to
collector
values
- the collection of valuescollector
- the resulting mapincludeNulls
- whether or not null
evaluations should be includedpublic final <V> java.util.List<K> collect(java.lang.Iterable<V> values, boolean includeNulls)
values
applying this
to
each instance of V
and adding the results of the evaluations to
the returned list.
values
- the collection of valuesincludeNulls
- whether or not null
evaluations should be included
public final <V> java.util.List<K> collect(java.lang.Iterable<V> values)
values
applying this
to
each instance of V
and adding the results of the evaluations to
the returned list.
values
- the collection of values
public static <X> Function<X> make(java.lang.reflect.Method method)
Function
based on
the supplied Method
.
public static <X> Function<X> make(java.lang.Class cls, java.lang.String methodName, java.lang.Class... argumentTypes) throws java.lang.NoSuchMethodException
Function
based on
the supplied Method
.
java.lang.NoSuchMethodException
public static <X> Function<X> identity()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |