Class NamedFormatter

java.lang.Object
org.elasticsearch.common.util.NamedFormatter

public class NamedFormatter extends Object
A formatter that allows named placeholders e.g. "%(param)" to be replaced.
  • Method Details

    • format

      public static String format(String fmt, Map<String,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 the values 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