Package org.elasticsearch.common.util
Class NamedFormatter
java.lang.Object
org.elasticsearch.common.util.NamedFormatter
A formatter that allows named placeholders e.g. "%(param)" to be replaced.
-
Method Summary
-
Method Details
-
format
Replaces named parameters of the form%(param)
in format strings. For example:NamedFormatter.format("Hello, %(name)!", Map.of("name", "world"))
→"Hello, world!"
NamedFormatter.format("Hello, \%(name)!", Map.of("name", "world"))
→"Hello, %(world)!"
NamedFormatter.format("Hello, %(oops)!", Map.of("name", "world"))
→IllegalArgumentException
- Parameters:
fmt
- The format string. Any%(param)
is replaced by its corresponding value in thevalues
map. Parameter patterns can be escaped by prefixing with a backslash.values
- a map of parameter names to values.- Returns:
- The formatted string.
- Throws:
IllegalArgumentException
- if a parameter is found in the format string with no corresponding value
-