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
A function-based lookup where the request for a lookup is answered by applying that function with a key.
- Since:
- 1.9
-
Field Summary
FieldsFields inherited from class org.apache.commons.text.lookup.AbstractStringLookup
SPLIT_CH, SPLIT_STR
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
FunctionStringLookup
(Function<String, V> function) Creates a new instance backed by a Function. -
Method Summary
Modifier and TypeMethodDescriptionLooks up a String key by applying the function.(package private) static <R> FunctionStringLookup
<R> Creates a new instance backed by a Function.(package private) static <V> FunctionStringLookup
<V> Creates a new instance backed by a Map.toString()
Methods inherited from class org.apache.commons.text.lookup.AbstractStringLookup
substringAfter, substringAfter, substringAfterLast, toLookupKey, toLookupKey
-
Field Details
-
function
Function.
-
-
Constructor Details
-
FunctionStringLookup
Creates a new instance backed by a Function.- Parameters:
function
- the function, may be null.
-
-
Method Details
-
on
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
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
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.
-
toString
-