Package org.apache.commons.text.lookup
Class FunctionStringLookup<V>
- java.lang.Object
-
- org.apache.commons.text.lookup.AbstractStringLookup
-
- org.apache.commons.text.lookup.FunctionStringLookup<V>
-
- Type Parameters:
V- A function's input type
- All Implemented Interfaces:
StringLookup
final class FunctionStringLookup<V> extends AbstractStringLookup
A function-based lookup where the request for a lookup is answered by applying that function with a key.- Since:
- 1.9
-
-
Field Summary
-
Fields inherited from class org.apache.commons.text.lookup.AbstractStringLookup
SPLIT_CH, SPLIT_STR
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringlookup(String key)Looks up a String key by applying the function.(package private) static <R> FunctionStringLookup<R>on(Function<String,R> function)Creates a new instance backed by a Function.(package private) static <V> FunctionStringLookup<V>on(Map<String,V> map)Creates a new instance backed by a Map.StringtoString()-
Methods inherited from class org.apache.commons.text.lookup.AbstractStringLookup
substringAfter, substringAfter, substringAfterLast, toLookupKey, toLookupKey
-
-
-
-
Method Detail
-
on
static <R> FunctionStringLookup<R> on(Function<String,R> function)
Creates a new instance backed by a Function.- Type Parameters:
R- the function's input type- Parameters:
function- the function, may be null.- Returns:
- a new instance backed by the given function.
-
on
static <V> FunctionStringLookup<V> on(Map<String,V> map)
Creates a new instance backed by a Map. Used by the default lookup.- Type Parameters:
V- the map's value type.- Parameters:
map- the map of keys to values, may be null.- Returns:
- a new instance backed by the given map.
-
lookup
public String lookup(String key)
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- the key to be looked up, may be null.- Returns:
- The function result as a string, may be null.
-
-