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 Modifier and Type Field Description private java.util.function.Function<java.lang.String,V>
function
Function.-
Fields inherited from class org.apache.commons.text.lookup.AbstractStringLookup
SPLIT_CH, SPLIT_STR
-
-
Constructor Summary
Constructors Modifier Constructor Description private
FunctionStringLookup(java.util.function.Function<java.lang.String,V> function)
Creates a new instance backed by a Function.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
lookup(java.lang.String key)
Looks up a String key by applying the function.(package private) static <R> FunctionStringLookup<R>
on(java.util.function.Function<java.lang.String,R> function)
Creates a new instance backed by a Function.(package private) static <V> FunctionStringLookup<V>
on(java.util.Map<java.lang.String,V> map)
Creates a new instance backed by a Map.java.lang.String
toString()
-
Methods inherited from class org.apache.commons.text.lookup.AbstractStringLookup
substringAfter, substringAfter, substringAfterLast, toLookupKey, toLookupKey
-
-
-
-
Field Detail
-
function
private final java.util.function.Function<java.lang.String,V> function
Function.
-
-
Constructor Detail
-
FunctionStringLookup
private FunctionStringLookup(java.util.function.Function<java.lang.String,V> function)
Creates a new instance backed by a Function.- Parameters:
function
- the function, may be null.
-
-
Method Detail
-
on
static <R> FunctionStringLookup<R> on(java.util.function.Function<java.lang.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(java.util.Map<java.lang.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 java.lang.String lookup(java.lang.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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-