Class 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 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 class java.lang.Object