Package org.elasticsearch.common.util
Class NamedFormatter
java.lang.Object
org.elasticsearch.common.util.NamedFormatter
public class NamedFormatter
extends java.lang.Object
A formatter that allows named placeholders e.g. "%(param)" to be replaced.
-
Method Summary
Modifier and Type Method Description static java.lang.String
format(java.lang.String fmt, java.util.Map<java.lang.String,java.lang.Object> values)
Replaces named parameters of the form%(param)
in format strings.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Method Details
-
format
public static java.lang.String format(java.lang.String fmt, java.util.Map<java.lang.String,java.lang.Object> values)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:
java.lang.IllegalArgumentException
- if a parameter is found in the format string with no corresponding value
-