Top Description Inners Constructors Methods
com.google.common.base

public final Class Functions

extends Object
Class Inheritance
Annotations
@GwtCompatible
@ElementTypesAreNonnullByDefault
Static Imports
com.google.common.base.NullnessCasts.uncheckedCastNullableTToT, .Preconditions.checkArgument, .Preconditions.checkNotNull

Static utility methods pertaining to com.google.common.base.Function instances; see that class for information about migrating to java.util.function.

All methods return serializable functions as long as they're given serializable parameters.

See the Guava User Guide article on the use of Function.

Authors
Mike Bostock, Jared Levy
Since
2.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
private static enum
private static class
private static class
private static enum

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <A extends @Nullable Object, B extends @Nullable Object, C extends @Nullable Object> Function<A, C>

Returns:

the composition of f and g
compose
(Function<B, C>
the second function to apply
g
,
Function<A, ? extends B>
the first function to apply
f
)

Returns the composition of two functions.

public static <E extends @Nullable Object> Function<@Nullable Object, E>

Returns:

a function that always returns value
constant
(E
the constant value for the function to return
value
)

Returns a function that ignores its input and always returns value.

public static <K extends @Nullable Object, V extends @Nullable Object> Function<K, V>
forMap(Map<K, V> map)

Returns a function which performs a map lookup.

public static <K extends @Nullable Object, V extends @Nullable Object> Function<K, V>

Returns:

function that returns map.get(a) when a is a key, or defaultValue otherwise
forMap
(Map<K, ? extends V>
source map that determines the function behavior
map
,
V
the value to return for inputs that aren't map keys
defaultValue
)

Returns a function which performs a map lookup with a default value.

public static <T extends @Nullable Object> Function<T, Boolean>
forPredicate(Predicate<T> predicate)

Creates a function that returns the same boolean output as the given predicate for all inputs.

public static <F extends @Nullable Object, T extends @Nullable Object> Function<F, T>
forSupplier(Supplier<T> supplier)

Returns a function that ignores its input and returns the result of supplier.get().

public static <E extends @Nullable Object> Function<E, E>
identity()

Returns the identity function.

public static Function<Object, String>
toStringFunction()

A function equivalent to the method reference Object::toString, for users not yet using Java 8.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait