|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.google.common.base.Functions
public final class Functions
Useful functions.
| Field Summary | |
|---|---|
static Function<Object,String> |
TO_STRING
A function that returns Object.toString() of its argument. |
| Method Summary | ||
|---|---|---|
static
|
compose(Function<B,C> g,
Function<A,? extends B> f)
Returns a compostion g<sup>0</sup>f : A->C of two functions,
f: A->B and g: B->C. |
|
static
|
constant(E value)
Returns a Function that returns value for any input. |
|
static
|
forMap(Map<A,? extends B> map,
B defaultValue)
Returns a function which performs key-to-value lookup on map. |
|
static
|
forMap(Map<A,B> map)
Returns a function which performs key-to-value lookup on map. |
|
static
|
forPredicate(Predicate<? super T> predicate)
Returns a boolean-valued function that evaluates to the same result as the given predicate. |
|
static
|
identity()
Returns the identity Function. |
|
static
|
narrow(Function<? super A,? extends B> function)
Casts a Function to a more restrictive type for use with methods
requiring unnecessarily specific Function types. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Function<Object,String> TO_STRING
Object.toString() of its argument.
Note that this function is not @Nullable: it will throw a
NullPointerException when applied to null.
Note also that this is assignable to variables of type
Function<? super E, String>, but not
Function<E, String>.
| Method Detail |
|---|
public static <E> Function<E,E> identity()
public static <A,B> Function<A,B> forMap(Map<A,B> map)
map.
The difference between a map and a function is that a map is defined on
a set of keys, while a function is defined on a type.
The function built by this method returns null
for all its arguments that do not belong to the map's keyset.
map - Map<A,B> source map
public static <A,B> Function<A,B> forMap(Map<A,? extends B> map,
@Nullable
B defaultValue)
map.
The function built by this method returns defaultValue
for all its arguments that do not belong to the map's keyset.
map - Map<A,B>defaultValue - B
f such that f(a)=map.get(a)
if map.containsKey(x), and defaultValue otherwise.forMap(Map)
public static <A,B,C> Function<A,C> compose(Function<B,C> g,
Function<A,? extends B> f)
g<sup>0</sup>f : A->C of two functions,
f: A->B and g: B->C.
Compostion is defined as a function h such that
h(x) = g(f(x)) for each x.
g - Function<B,C>f - Function<A,B>
public static <T> Function<T,Boolean> forPredicate(Predicate<? super T> predicate)
public static <E> Function<Object,E> constant(@Nullable
E value)
Function that returns value for any input.
value - the constant value for the Function to return
Function that always returns value.
public static <A,B> Function<A,B> narrow(@Nullable
Function<? super A,? extends B> function)
Function to a more restrictive type for use with methods
requiring unnecessarily specific Function types.
If you find that a Function (such as
constant(Object), a Function<Object, Bar>) does
not work with your code because you require a Function<Foo, Bar> to
pass to a method, then that method should require a
Function<? super Foo, ? extends Bar>. Any such Function is
capable of taking a Foo as an argument and returning a Bar.
If the code you are calling is part of a third-party library and cannot be
fixed, you can, as a last resort, use this method to cast the returned
Function to the required type.
function - the original Function
Function with the same behavior but more restrictive type
parameters
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||