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 Details

  • Constructor Details

    • FunctionStringLookup

      private FunctionStringLookup(Function<String,V> function)
      Creates a new instance backed by a Function.
      Parameters:
      function - the function, may be null.
  • Method Details

    • 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.
    • toString

      public String toString()
      Overrides:
      toString in class Object