Interface IStringTemplate


public interface IStringTemplate
Represents a template string which can be evaluated on demand.
  • Method Details

    • getParameters

      List<ITemplateParameter> getParameters()
      Returns the list of template parameters.
      Returns:
      the parameters
    • toString

      String toString()
      Evaluates the template string.
      Overrides:
      toString in class Object
      Returns:
      the evaluated string
    • getTemplate

      String getTemplate()
      Returns the template string, containing placeholders for the parameters.
      Returns:
      the template string
    • replacePlaceholders

      String replacePlaceholders(BiFunction<String,Integer,String> replacer)
      Replaces each template placeholder with the output of the replacer function. The replacer function will receive each placeholder and its index as parameters.

      Example:

           // Making template parameter indices zero based instead of one based
           // The template "Hello {1} {2}!" will be converted to "Hello {0} {1}!"
           template.replacePlaceholders((parameter, index) -> String.format("{%d}", index - 1));
       
      Parameters:
      replacer - the function to replace placeholders by the proper values
      Returns:
      the template string with replaced placeholders