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

pack-priv final Class BiFunctionStringLookup<P, R>

extends Object
implements BiStringLookup<P>
Class Inheritance
All Implemented Interfaces
org.apache.commons.text.lookup.BiStringLookup, org.apache.commons.text.lookup.StringLookup, java.util.function.UnaryOperator, java.util.function.Function
Type Parameters
<P>
A function's second input type
<R>
A function's return type
Imports
java.util.Map, .Objects, java.util.function.BiFunction

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 BiFunction<String, P, R>
biFunction

Function.

Constructor Summary

AccessConstructor and Description
private
BiFunctionStringLookup(final BiFunction<String, P, R>
the function, may be null.
biFunction
)

Creates a new instance backed by a Function.

Method Summary

Modifier and TypeMethod and Description
public String
lookup(final String key)

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

Looks up a String key to provide a String value.

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
,
final P object)

Overrides default org.apache.commons.text.lookup.BiStringLookup.lookup.

Looks up a String key by applying the function.

pack-priv static <U,
the function's input type
T
>
BiFunctionStringLookup<U, T>

Returns:

a new instance backed by the given function.
on
(final BiFunction<String, U, T>
the function, may be null.
biFunction
)

Creates a new instance backed by a Function.

pack-priv static <U,
the map's value type.
T
>
BiFunctionStringLookup<U, T>

Returns:

a new instance backed by the given map.
on
(final Map<String, T>
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 java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

biFunctionback to summary
private final BiFunction<String, P, R> biFunction

Function.

Constructor Detail

BiFunctionStringLookupback to summary
private BiFunctionStringLookup(final BiFunction<String, P, R> biFunction)

Creates a new instance backed by a Function.

Parameters
biFunction:BiFunction<String, P, R>

the function, may be null.

Method Detail

lookupback to summary
public String lookup(final String key)

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

Doc from org.apache.commons.text.lookup.StringLookup.lookup.

Looks up a String key to provide a String value.

The internal implementation may use any mechanism to return the value. The simplest implementation is to use a Map. However, virtually any implementation is possible.

For example, it would be possible to implement a lookup that used the key as a primary key, and looked up the value on demand from the database Or, a numeric based implementation could be created that treats the key as an integer, increments the value and return the result as a string - converting 1 to 2, 15 to 16 etc.

This method always returns a String, regardless of the underlying data, by converting it as necessary. For example:

Map<String, Object> map = new HashMap<String, Object>();
map.put("number", Integer.valueOf(2));
assertEquals("2", StringLookupFactory.mapStringLookup(map).lookup("number"));
Annotations
@Override
lookupback to summary
public String lookup(final String key, final P object)

Overrides default org.apache.commons.text.lookup.BiStringLookup.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 <U, T> BiFunctionStringLookup<U, T> on(final BiFunction<String, U, T> biFunction)

Creates a new instance backed by a Function.

Parameters
<T>
the function's input type
biFunction:BiFunction<String, U, T>

the function, may be null.

Returns:BiFunctionStringLookup<U, T>

a new instance backed by the given function.

onback to summary
pack-priv static <U, T> BiFunctionStringLookup<U, T> on(final Map<String, T> map)

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

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

the map of keys to values, may be null.

Returns:BiFunctionStringLookup<U, T>

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