|
||||||||||
| 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<java.lang.Object,java.lang.String> |
TO_STRING
See toStringFunction(). |
static Function<java.lang.String,java.lang.String> |
TRIM_STRING
See trimString(). |
| Method Summary | ||
|---|---|---|
static
|
compose(Function<? super B,? extends C> g,
Function<? super A,? extends B> f)
Returns the composition of two functions. |
|
static
|
constant(E value)
Returns a Function that returns value for any input. |
|
static
|
forMap(java.util.Map<? super A,? extends B> map)
Returns a function which performs key-to-value lookup on map. |
|
static
|
forMap(java.util.Map<? super A,? extends B> map,
B defaultValue)
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 Function<java.lang.Object,java.lang.Integer> |
toHashCode()
Returns a function that determines the Object.hashCode() of its
argument. |
|
static
|
toStringFunction()
Returns a function that returns the Object.toString() value of its
argument. |
|
static Function<java.lang.String,java.lang.String> |
trimString()
A function that returns the result of calling String.trim()
on its argument. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final Function<java.lang.Object,java.lang.String> TO_STRING
toStringFunction().
TODO: Consider deprecating this in favor of an accessor method like
toStringFunction().
public static final Function<java.lang.String,java.lang.String> TRIM_STRING
trimString().
TODO: Deprecate this and use trimString().
| Method Detail |
|---|
public static <F> Function<F,java.lang.String> toStringFunction()
Object.toString() value of its
argument. This function is not nullable; invoking apply(null) on it
throws a NullPointerException.
public static Function<java.lang.Object,java.lang.Integer> toHashCode()
Object.hashCode() of its
argument. For null arguments, this returns 0, as used in hash code
calculations by the Java Collections classes.
public static Function<java.lang.String,java.lang.String> trimString()
String.trim()
on its argument. Note that this function is not @Nullable:
it will throw a NullPointerException when applied to null.
public static <E> Function<E,E> identity()
public static <A,B> Function<A,B> forMap(java.util.Map<? super A,? extends 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 arguments that do not belong to the map's keyset.
map - Map<A,B> source map
public static <A,B> Function<A,B> forMap(java.util.Map<? super 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<? super B,? extends C> g,
Function<? super A,? extends B> f)
f: A->B and
g: B->C, composition is defined as the 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,java.lang.Boolean> forPredicate(Predicate<? super T> predicate)
public static <E> Function<java.lang.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.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||