Top Description Fields Constructors Methods
org.apache.commons.text.lookup

pack-priv final Class FunctionStringLookup<V>

extends AbstractStringLookup
Class Inheritance
Type Parameters
<V>
A function's input type
Imports
java.util.Map, .Objects, java.util.function.Function

A function-based lookup where the request for a lookup is answered by applying that function with a key.

Public access is through StringLookupFactory.

Since
1.9
See Also
StringLookupFactory

Field Summary

Modifier and TypeField and Description
private final Function<String, V>
function

Function.

Inherited from org.apache.commons.text.lookup.AbstractStringLookup:
SPLIT_CHSPLIT_STR

Constructor Summary

AccessConstructor and Description
private
FunctionStringLookup(final Function<String, V>
the function, may be null.
function
)

Creates a new instance backed by a Function.

Method Summary

Modifier and TypeMethod and Description
public String

Returns:

The function result as a string, may be null.
lookup
(final String
the key to be looked up, may be null.
key
)

Implements org.apache.commons.text.lookup.StringLookup.lookup.

Looks up a String key by applying the function.

pack-priv static <
the function's input type
R
>
FunctionStringLookup<R>

Returns:

a new instance backed by the given function.
on
(final Function<String, R>
the function, may be null.
function
)

Creates a new instance backed by a Function.

pack-priv static <
the map's value type.
V
>
FunctionStringLookup<V>

Returns:

a new instance backed by the given map.
on
(final Map<String, V>
the map of keys to values, may be null.
map
)

Creates a new instance backed by a Map.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.apache.commons.text.lookup.AbstractStringLookup:
substringAftersubstringAftersubstringAfterLasttoLookupKeytoLookupKey

Field Detail

functionback to summary
private final Function<String, V> function

Function.

Constructor Detail

FunctionStringLookupback to summary
private FunctionStringLookup(final Function<String, V> function)

Creates a new instance backed by a Function.

Parameters
function:Function<String, V>

the function, may be null.

Method Detail

lookupback to summary
public String lookup(final String key)

Implements org.apache.commons.text.lookup.StringLookup.lookup.

Looks up a String key by applying the function.

If the function is null, then null is returned. The function result object is converted to a string using toString().

Parameters
key:String

the key to be looked up, may be null.

Returns:String

The function result as a string, may be null.

Annotations
@Override
onback to summary
pack-priv static <R> FunctionStringLookup<R> on(final Function<String, R> function)

Creates a new instance backed by a Function.

Parameters
<R>
the function's input type
function:Function<String, R>

the function, may be null.

Returns:FunctionStringLookup<R>

a new instance backed by the given function.

onback to summary
pack-priv static <V> FunctionStringLookup<V> on(final Map<String, V> map)

Creates a new instance backed by a Map. Used by the default lookup.

Parameters
<V>
the map's value type.
map:Map<String, V>

the map of keys to values, may be null.

Returns:FunctionStringLookup<V>

a new instance backed by the given map.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override