Class InterpolatorStringLookup

java.lang.Object
org.apache.commons.text.lookup.AbstractStringLookup
org.apache.commons.text.lookup.InterpolatorStringLookup
All Implemented Interfaces:
StringLookup

class InterpolatorStringLookup extends AbstractStringLookup
Proxies other StringLookups using a keys within ${} markers using the format "${StringLookup:Key}".

Uses the default lookups.

  • Field Details

    • INSTANCE

      static final AbstractStringLookup INSTANCE
      Defines the singleton for this class.
      Since:
      1.6
    • PREFIX_SEPARATOR

      private static final char PREFIX_SEPARATOR
      Constant for the prefix separator.
      See Also:
    • defaultStringLookup

      private final StringLookup defaultStringLookup
      The default string lookup.
    • stringLookupMap

      private final Map<String,StringLookup> stringLookupMap
      The map of String lookups keyed by prefix.
  • Constructor Details

    • InterpolatorStringLookup

      InterpolatorStringLookup()
      Creates an instance using only lookups that work without initial properties and are stateless.

      Uses the default lookups.

    • InterpolatorStringLookup

      InterpolatorStringLookup(Map<String,StringLookup> stringLookupMap, StringLookup defaultStringLookup, boolean addDefaultLookups)
      Creates a fully customized instance.
      Parameters:
      stringLookupMap - the map of string lookups.
      defaultStringLookup - the default string lookup.
      addDefaultLookups - whether the default lookups should be used.
    • InterpolatorStringLookup

      InterpolatorStringLookup(Map<String,V> defaultMap)
      Creates an instance using only lookups that work without initial properties and are stateless.

      Uses the default lookups.

      Type Parameters:
      V - the map's value type.
      Parameters:
      defaultMap - the default map for string lookups.
    • InterpolatorStringLookup

      InterpolatorStringLookup(StringLookup defaultStringLookup)
      Creates an instance with the given lookup.
      Parameters:
      defaultStringLookup - the default lookup.
  • Method Details

    • toKey

      static String toKey(String key)
    • getStringLookupMap

      public Map<String,StringLookup> getStringLookupMap()
      Gets the lookup map.
      Returns:
      The lookup map.
    • lookup

      public String lookup(String var)
      Resolves the specified variable. This implementation will try to extract a variable prefix from the given variable name (the first colon (':') is used as prefix separator). It then passes the name of the variable with the prefix stripped to the lookup object registered for this prefix. If no prefix can be found or if the associated lookup object cannot resolve this variable, the default lookup object will be used.
      Parameters:
      var - the name of the variable whose value is to be looked up
      Returns:
      The value of this variable or null if it cannot be resolved
    • toString

      public String toString()
      Overrides:
      toString in class Object