Class MultiVariableExpander

  • All Implemented Interfaces:
    VariableExpander

    public class MultiVariableExpander
    extends java.lang.Object
    implements VariableExpander

    Expands variable references from multiple sources.

    Since:
    1.6
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.ArrayList<java.lang.String> markers  
      private int nEntries  
      private java.util.ArrayList<java.util.Map<java.lang.String,​java.lang.Object>> sources  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addSource​(java.lang.String marker, java.util.Map<java.lang.String,​java.lang.Object> source)
      Add a new variables source, identified by the input marker
      java.lang.String expand​(java.lang.String param)
      Return the input string with any variables replaced by their corresponding value.
      java.lang.String expand​(java.lang.String str, java.lang.String marker, java.util.Map<java.lang.String,​java.lang.Object> source)
      Replace any occurrences within the string of the form "marker{key}" with the value from source[key].
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • nEntries

        private int nEntries
      • markers

        private final java.util.ArrayList<java.lang.String> markers
      • sources

        private final java.util.ArrayList<java.util.Map<java.lang.String,​java.lang.Object>> sources
    • Constructor Detail

      • MultiVariableExpander

        public MultiVariableExpander()
    • Method Detail

      • addSource

        public void addSource​(java.lang.String marker,
                              java.util.Map<java.lang.String,​java.lang.Object> source)
        Add a new variables source, identified by the input marker
        Parameters:
        marker - The input variables marker
        source - The variables source
      • expand

        public java.lang.String expand​(java.lang.String param)
        Return the input string with any variables replaced by their corresponding value. If there are no variables in the string, then the input parameter is returned unaltered.
        Specified by:
        expand in interface VariableExpander
        Parameters:
        param - the string containing variables to be replaced.
        Returns:
        the input string with any variables replaced by their corresponding value.
      • expand

        public java.lang.String expand​(java.lang.String str,
                                       java.lang.String marker,
                                       java.util.Map<java.lang.String,​java.lang.Object> source)
        Replace any occurrences within the string of the form "marker{key}" with the value from source[key].

        Commonly, the variable marker is "$", in which case variables are indicated by ${key} in the string.

        Returns the string after performing all substitutions.

        If no substitutions were made, the input string object is returned (not a copy).

        Parameters:
        str - The input string containing placeholders
        marker - The input variables marker
        source - The variables source
        Returns:
        The input string where variables have been expanded by replacing values found in source