Class WoolVariableString


  • public class WoolVariableString
    extends Object
    This class represents a text with possible variables. It is modelled as a list of segments, where each segment is plain text or a variable.

    The segments are always normalized so that subsequent plain text segments are automatically merged into one.

    • Constructor Detail

      • WoolVariableString

        public WoolVariableString()
      • WoolVariableString

        public WoolVariableString​(String text)
    • Method Detail

      • getSegments

        public List<WoolVariableString.Segment> getSegments()
        Returns the segments as an unmodifiable list.
        Returns:
        the segments as an unmodifiable list
      • execute

        public WoolVariableString execute​(Map<String,​Object> variables)
        Executes this variable string with respect to the specified variables. The result will be a string with 0 or 1 text segments. Undefined variables will be evaluated as string "null".
        Parameters:
        variables - the variable map (can be null)
        Returns:
        the processed variable string
      • evaluate

        public String evaluate​(Map<String,​Object> variables)
        Evaluates this variable string with respect to the specified variables. Undefined variables will be evaluated as string "null".
        Parameters:
        variables - the variable map (can be null)
        Returns:
        the evaluated string
      • getReadVariableNames

        public void getReadVariableNames​(Set<String> varNames)
        Retrieves all variable names that are read in this variable string and adds them to the specified set.
        Parameters:
        varNames - the set to which the variable names are added
      • isWhitespace

        public boolean isWhitespace()
      • isPlainText

        public boolean isPlainText()
      • trimWhitespace

        public void trimWhitespace()
      • removeLeadingWhitespace

        public void removeLeadingWhitespace()
      • removeTrailingWhitespace

        public void removeTrailingWhitespace()
      • toString

        public String toString​(char[] escapes)
        Returns the code string for this instance. It will escape \ and $ with a backslash. You may specify additional characters to escape.
        Parameters:
        escapes - the characters to escape
        Returns:
        the code string