|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.google.common.base.Functions
public final class Functions
Useful functions.
All methods returns serializable functions as long as they're given serializable parameters.
Method Summary | ||
---|---|---|
static
|
compose(Function<B,C> g,
Function<A,? extends B> f)
Returns the composition of two functions. |
|
static
|
constant(E value)
Creates a function that returns value for any input. |
|
static
|
forMap(Map<K,? extends V> map,
V defaultValue)
Returns a function which performs a map lookup with a default value. |
|
static
|
forMap(Map<K,V> map)
Returns a function which performs a map lookup. |
|
static
|
forPredicate(Predicate<T> predicate)
Creates a function that returns the same boolean output as the given predicate for all inputs. |
|
static
|
identity()
Returns the identity function. |
|
static Function<Object,String> |
toStringFunction()
Returns a function that calls toString() on its argument. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static Function<Object,String> toStringFunction()
toString()
on its argument. The function does not accept
nulls; it will throw a NullPointerException
when applied to null
.
public static <E> Function<E,E> identity()
public static <K,V> Function<K,V> forMap(Map<K,V> map)
IllegalArgumentException
if given a key that does not exist in the map.
public static <K,V> Function<K,V> forMap(Map<K,? extends V> map, @Nullable V defaultValue)
defaultValue
for all inputs that do not belong to the map's key
set.
map
- source map that determines the function behaviordefaultValue
- the value to return for inputs that aren't map keys
map.get(a)
when a
is a key, or defaultValue
otherwisepublic static <A,B,C> Function<A,C> compose(Function<B,C> g, Function<A,? extends B> f)
f: A->B
and g: B->C
, composition
is defined as the function h such that h(a) == g(f(a))
for each a
.
g
- the second function to applyf
- the first function to apply
f
and g
public static <T> Function<T,Boolean> forPredicate(Predicate<T> predicate)
public static <E> Function<Object,E> constant(@Nullable E value)
value
for any input.
value
- the constant value for the function to return
value
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |