|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jjoost.util.Functions
public class Functions
A class defining simple functions, and methods for working with functions
| Nested Class Summary | |
|---|---|
static class |
Functions.AbstractValueProjection<E extends Value<V>,V>
A function that retrieves the value from a Value |
static class |
Functions.FieldProjection<E,F>
A Function which accepts a Field (reflection API), which will be retrieved and returned
from every object the function is applied to. |
static class |
Functions.MapEntryKeyProjection<E extends java.util.Map.Entry<K,?>,K>
A function that retrieves the key portion of a Map.Entry |
static class |
Functions.MapEntryValueProjection<E extends java.util.Map.Entry<?,V>,V>
A function that retrieves the value portion of a Map.Entry |
static class |
Functions.MethodProjection<E,F>
A Function which accepts a Method and arguments to provide to the method, which will execute the method on
each object it receives as an argument, returning the result. |
| Constructor Summary | |
|---|---|
Functions()
|
|
| Method Summary | ||
|---|---|---|
static
|
apply(ClosableIterator<? extends E> iter,
Function<? super E,? extends F> f)
/** Returns a new iterator which returns f.f(iter.next()) for each call to next() in the resulting iterator. |
|
static
|
apply(Function<? super E,? extends F> f,
ClosableIterator<? extends E> iter)
Returns a new iterator which returns f.f(iter.next()) for each call to next() in the resulting iterator. |
|
static
|
apply(Function<? super E,? extends F> f,
java.lang.Iterable<? extends E> iter)
Returns a new Iterable which lazily applies the provided function to all iterators constructed from it. |
|
static
|
apply(Function<? super E,? extends F> f,
java.util.Iterator<? extends E> iter)
Returns a new iterator which returns f.f(iter.next()) for each call to next() in the resulting iterator. |
|
static
|
apply(Function<? super E,? extends F> f,
java.util.List<? extends E> list)
Creates a new ArrayList that contains the result of applying the provided function to every element in the provided
list. |
|
static
|
apply(java.lang.Iterable<? extends E> iter,
Function<? super E,? extends F> f)
Returns a new Iterable which lazily applies the provided function to all iterators constructed from it. |
|
static
|
apply(java.util.Iterator<? extends E> iter,
Function<? super E,? extends F> f)
Returns a new iterator which returns f.f(iter.next()) for each call to next() in the resulting iterator. |
|
static
|
apply(java.util.List<? extends E> list,
Function<? super E,? extends F> f)
Creates a new ArrayList that contains the result of applying the provided function to every element in the provided list. |
|
static
|
composition(Function<F,G> f2,
Function<E,F> f1)
Returns a function that is the composition of the two provided functions; the function provided as the second argument is applied first, and the function provided as the first argument is then applied to the result of this, i.e. |
|
static
|
getFieldProjection(java.lang.Class<E> clazz,
java.lang.String propertyName,
java.lang.Class<F> propertyType)
Return a Function which retrieves the named field from each object it is applied to |
|
static
|
getMapEntryKeyProjection()
Return a function that retrieves the key portion of a Map.Entry |
|
static
|
getMapEntryValueProjection()
Return a function that retrieves the value portion of a Map.Entry |
|
static
|
getMethodProjection(java.lang.Class<E> clazz,
java.lang.String methodName,
java.lang.Class<F> returnType)
Return a Function which executes the named no-arg method on objects of the provided type |
|
static
|
getValueContentsProjection()
Return a function that retrieves the value from a Value object |
|
static
|
identity()
Returns the identity function, i.e. |
|
static
|
replaceNullWith(E val)
Returns a function that for all non-null inputs acts like the identity function (i.e. |
|
static
|
toString(boolean replaceNulls)
Returns a function that converts its input to a String; if replaceNulls is true then
null values are replaced by "null", otherwise they are left as null |
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Functions()
| Method Detail |
|---|
public static <E> Function<E,E> identity()
E - input type
public static <E> Function<E,java.lang.String> toString(boolean replaceNulls)
String; if replaceNulls is true then
null values are replaced by "null", otherwise they are left as null
replaceNulls - if true, replace nulls with "null"
Stringpublic static <E> Function<E,E> replaceNullWith(E val)
val - value to replace nulls with
public static <E,F,G> Function<E,G> composition(Function<F,G> f2,
Function<E,F> f1)
f2.apply(f1.apply(v))
f2 - function applied secondf1 - function applied first
public static <E,F> Function<E,F> getMethodProjection(java.lang.Class<E> clazz,
java.lang.String methodName,
java.lang.Class<F> returnType)
throws java.lang.SecurityException,
java.lang.NoSuchMethodException
clazz - function input typemethodName - name of the method to callreturnType - the return type of the method
java.lang.SecurityException - if a SecurityManager prevents access to the method
java.lang.NoSuchMethodException - if no no-args method of the provided name can be found in the provided class' hierarchy
public static <E,F> Function<E,F> getFieldProjection(java.lang.Class<E> clazz,
java.lang.String propertyName,
java.lang.Class<F> propertyType)
throws java.lang.SecurityException,
java.lang.NoSuchFieldException
clazz - the input type of the functionpropertyName - the name of the propertypropertyType - the type of the property
java.lang.SecurityException - if a SecurityManager prevents access to the method
java.lang.NoSuchFieldException - if a field of the provided name could not be found in the provided classpublic static <V,E extends java.util.Map.Entry<?,? extends V>> Function<E,V> getMapEntryValueProjection()
Map.Entry
Map.Entrypublic static <K,E extends java.util.Map.Entry<? extends K,?>> Function<E,K> getMapEntryKeyProjection()
Map.Entry
Map.Entrypublic static <V> Function<Value<V>,V> getValueContentsProjection()
Value object
Value object
public static <E,F> java.util.List<F> apply(Function<? super E,? extends F> f,
java.util.List<? extends E> list)
ArrayList that contains the result of applying the provided function to every element in the provided
list. Equivalent to apply(list, f).
list - list to apply the function tof - function to apply to the list
ArrayList that contains the result of applying the provided function to every element in the provided list
public static <E,F> java.util.List<F> apply(java.util.List<? extends E> list,
Function<? super E,? extends F> f)
ArrayList that contains the result of applying the provided function to every element in the provided list.
Equivalent to apply(f, list).
list - list to apply the function tof - function to apply to the list
ArrayList that contains the result of applying the provided function to every element in the provided list
public static <E,F> java.lang.Iterable<F> apply(Function<? super E,? extends F> f,
java.lang.Iterable<? extends E> iter)
Iterable which lazily applies the provided function to all iterators constructed from it.
Equivalent to apply(iter, f).
iter - iterable to apply the function tof - function to apply to the iterable
Iterable which lazily applies the provided function to all iterators constructed from it
public static <E,F> java.lang.Iterable<F> apply(java.lang.Iterable<? extends E> iter,
Function<? super E,? extends F> f)
Iterable which lazily applies the provided function to all iterators constructed from it.
Equivalent to apply(f, iter).
iter - iterable to apply the function tof - function to apply to the iterable
Iterable which lazily applies the provided function to all iterators constructed from it
public static <E,F> java.util.Iterator<F> apply(java.util.Iterator<? extends E> iter,
Function<? super E,? extends F> f)
f.f(iter.next()) for each call to next() in the resulting iterator.
Equivalent to apply(f, iter).
iter - iterator to apply the function tof - function to apply to the iterator
f.f(iter.next()) for each call to next()
public static <E,F> java.util.Iterator<F> apply(Function<? super E,? extends F> f,
java.util.Iterator<? extends E> iter)
f.f(iter.next()) for each call to next() in the resulting iterator.
Equivalent to apply(iter, f).
iter - iterator to apply the function tof - function to apply to the iterator
f.f(iter.next()) for each call to next()
public static <E,F> ClosableIterator<F> apply(ClosableIterator<? extends E> iter,
Function<? super E,? extends F> f)
f.f(iter.next()) for each call to next() in the resulting iterator.
Equivalent to apply(f, iter).
iter - iterator to apply the function tof - function to apply to the iterator
f.f(iter.next()) for each call to next()
public static <E,F> ClosableIterator<F> apply(Function<? super E,? extends F> f,
ClosableIterator<? extends E> iter)
f.f(iter.next()) for each call to next() in the resulting iterator.
Equivalent to apply(iter, f).
iter - iterator to apply the function tof - function to apply to the iterator
f.f(iter.next()) for each call to next()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||