Package org.apache.commons.text.lookup
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 otherStringLookup
s using a keys within ${} markers using the format "${StringLookup:Key}".Uses the
default lookups
.
-
-
Field Summary
Fields Modifier and Type Field Description private StringLookup
defaultStringLookup
The default string lookup.(package private) static AbstractStringLookup
INSTANCE
Defines the singleton for this class.private static char
PREFIX_SEPARATOR
Constant for the prefix separator.private java.util.Map<java.lang.String,StringLookup>
stringLookupMap
The map of String lookups keyed by prefix.-
Fields inherited from class org.apache.commons.text.lookup.AbstractStringLookup
SPLIT_CH, SPLIT_STR
-
-
Constructor Summary
Constructors Constructor Description InterpolatorStringLookup()
Constructs an instance using only lookups that work without initial properties and are stateless.InterpolatorStringLookup(java.util.Map<java.lang.String,StringLookup> stringLookupMap, StringLookup defaultStringLookup, boolean addDefaultLookups)
Constructs a fully customized instance.InterpolatorStringLookup(java.util.Map<java.lang.String,V> defaultMap)
Constructs an instance using only lookups that work without initial properties and are stateless.InterpolatorStringLookup(StringLookup defaultStringLookup)
Constructs an instance with the given lookup.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,StringLookup>
getStringLookupMap()
Gets the lookup map.java.lang.String
lookup(java.lang.String key)
Resolves the specified variable.java.lang.String
toString()
-
Methods inherited from class org.apache.commons.text.lookup.AbstractStringLookup
substringAfter, substringAfter, substringAfterLast, toLookupKey, toLookupKey
-
-
-
-
Field Detail
-
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:
- Constant Field Values
-
defaultStringLookup
private final StringLookup defaultStringLookup
The default string lookup.
-
stringLookupMap
private final java.util.Map<java.lang.String,StringLookup> stringLookupMap
The map of String lookups keyed by prefix.
-
-
Constructor Detail
-
InterpolatorStringLookup
InterpolatorStringLookup()
Constructs an instance using only lookups that work without initial properties and are stateless.Uses the
default lookups
.
-
InterpolatorStringLookup
InterpolatorStringLookup(java.util.Map<java.lang.String,StringLookup> stringLookupMap, StringLookup defaultStringLookup, boolean addDefaultLookups)
Constructs 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(java.util.Map<java.lang.String,V> defaultMap)
Constructs 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)
Constructs an instance with the given lookup.- Parameters:
defaultStringLookup
- the default lookup.
-
-
Method Detail
-
getStringLookupMap
public java.util.Map<java.lang.String,StringLookup> getStringLookupMap()
Gets the lookup map.- Returns:
- The lookup map.
-
lookup
public java.lang.String lookup(java.lang.String key)
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:
key
- 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 java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-