Package adams.core

Class Variables

    • Constructor Detail

      • Variables

        public Variables()
        Initializes the container.
    • Method Detail

      • clear

        public void clear()
        Removes all currently stored variables.
      • names

        public Enumeration<String> names()
        Returns an enumeration over the names of the variables.
        Returns:
        the names
      • nameSet

        public Set<String> nameSet()
        Returns a set containing the names of the variables.
        Returns:
        the names
      • set

        public void set​(String name,
                        String value)
        Stores the value for the variable.
        Parameters:
        name - the name (or placeholder string) of the variable
        value - the value of the variable
      • has

        public boolean has​(String name)
        Checks whether a variable is stored or not.
        Parameters:
        name - the name (or placeholder string) of the variable
        Returns:
        true if the variable is stored
      • get

        public String get​(String name)
        Returns the stored value if present, otherwise null.
        Parameters:
        name - the name (or placeholder string) of the variable
        Returns:
        the associated value or null if not found
      • remove

        public String remove​(String name)
        Removes the variable.
        Parameters:
        name - the name (or placeholder string) of the variable
        Returns:
        the previously stored value
      • remove

        public boolean remove​(BaseRegExp regExp)
        Removes variables that match a regular expressions.
        Parameters:
        regExp - the regular expression to match the name of the variables against
        Returns:
        true if at least one was removed
      • get

        public String get​(String name,
                          String defValue)
        Returns the stored value if present, otherwise the default value.
        Parameters:
        name - the name (or placeholder string) of the variable
        defValue - the default value, in case the variable is not stored
        Returns:
        the associated value
      • isObject

        public boolean isObject​(String name)
        Returns whether the stored value is present as non-string object.

        Default implementation always returns false.
        Returns:
        true if the value is stored as non-string
        See Also:
        getObject(String)
      • getObject

        public Object getObject​(String name)
        Returns the store value.
        Parameters:
        name - the name of the value
        Returns:
        the value referenced by the name, null if not available
        See Also:
        getObject(String,Object)
      • getObject

        public Object getObject​(String name,
                                Object defValue)
        Returns the store value.

        Default implementation simply returns get(String,String).
        Parameters:
        name - the name of the value
        defValue - the default value to use if value not present
        Returns:
        the value referenced by the name, defValue if not available
      • size

        public int size()
        Returns the number of variables currently stored.
        Returns:
        the number of variables
      • hasVariableChangeListener

        public boolean hasVariableChangeListener​(VariableChangeListener l)
        Checks whether the listener is in the internal list.
        Parameters:
        l - the listener to check
        Returns:
        true if already in the list
      • addVariableChangeListener

        public void addVariableChangeListener​(VariableChangeListener l)
        Adds the listener to the internal list.
        Parameters:
        l - the listener to add
      • removeVariableChangeListener

        public void removeVariableChangeListener​(VariableChangeListener l)
        Removes the listener from the internal list.
        Parameters:
        l - the listener to remove
      • removeVariableChangeListeners

        public void removeVariableChangeListeners()
        Removes all listeners from the internal list.
      • notifyVariableChangeListeners

        protected void notifyVariableChangeListeners​(VariableChangeEvent e)
        Notifies all listeners with the specified event.
        Parameters:
        e - the event to send
      • extractName

        public static String extractName​(String variable)
        Extracts the name of a variable from the placeholder string, i.e., it strips the "@{" and "}" from the string. Does nothing if already stripped.
        Parameters:
        variable - the variable placeholder
        Returns:
        the extracted name
        See Also:
        START, END
      • extractNames

        public static String[] extractNames​(String expr)
        Extracts all the variables from the given expression.
        Parameters:
        expr - the expression to parse for variable names
        Returns:
        the variable names located in the expression
      • padName

        public static String padName​(String name)
        Surrounds the variable name with "@{" and "}", if necessary.
        Parameters:
        name - the name to process
        Returns:
        the padded name
        See Also:
        START, END
      • isPlaceholder

        public static boolean isPlaceholder​(String s)
        Checks whether the string represents a variable placeholder, i.e., it starts with "@{" and ends with "}".
        Parameters:
        s - the string to check
        Returns:
        true if the string represents a variable placeholder string
      • isValidName

        public static boolean isValidName​(String s)
        Checks whether the string represents a valid name (without the "@{" and "}").
        Parameters:
        s - the name to check
        Returns:
        true if valid
      • createValidName

        public static String createValidName​(String s)
        Creates a valid variable name.
        Parameters:
        s - the name to turn into a valid variable name
        Returns:
        the processed name
      • toValidName

        public static String toValidName​(String s)
        Turns any string (with surrounding @{...}) into a valid variable name, by replacing invalid characters with underscores ("_").
        Parameters:
        s - the string to convert into a valid variable name
        Returns:
        the (potentially) fixed name
      • toValidName

        public static String toValidName​(String s,
                                         String replace)
        Turns any string (with surrounding @{...}) into a valid variable name, by replacing invalid characters with the specified replacement string.
        Parameters:
        s - the string to convert into a valid variable name
        replace - the replacement string for invalid chars
        Returns:
        the (potentially) fixed name
      • expand

        public String expand​(String s)
        Replaces all variables in the string with the currently stored values.
        Parameters:
        s - the string to process
        Returns:
        the processed string
      • doExpandEnv

        protected String doExpandEnv​(String s)
        Expands environment variables.
        Parameters:
        s - the string to expand
        Returns:
        the potentially expanded string
      • doExpandSystemProps

        protected String doExpandSystemProps​(String s)
        Expands system properties.
        Parameters:
        s - the string to expand
        Returns:
        the potentially expanded string
      • doExpandRegular

        protected String doExpandRegular​(String s)
        Expands regular variables.
        Parameters:
        s - the string to expand
        Returns:
        the potentially expanded string
      • doExpand

        protected String doExpand​(String s)
        Performs all expansions.
        Parameters:
        s - the string to expand
        Returns:
        the potentially expanded string
      • expand

        protected String expand​(String s,
                                boolean recurse)
        Replaces all variables in the string with the currently stored values.
        Parameters:
        s - the string to process
        recurse - whether to recurse, i.e., replacing "@{@{"
        Returns:
        the processed string
      • cleanUp

        public void cleanUp()
        Cleans up data structures, frees up memory.
        Specified by:
        cleanUp in interface CleanUpHandler
      • getClone

        public Variables getClone()
        Returns a clone of the object (but without the listeners).
        Specified by:
        getClone in interface CloneHandler<Variables>
        Returns:
        the clone, null if failed
      • getClone

        public Variables getClone​(BaseRegExp filter)
        Returns a clone of the object (but without the listeners).
        Parameters:
        filter - the regular expression that the variable names must match, null to ignore
        Returns:
        the clone, null if failed
      • assign

        public void assign​(Variables other)
        Adds all the variables from the other Variables object (overwrites any existing ones).
        Parameters:
        other - the Variables to copy
      • assign

        public void assign​(Variables other,
                           BaseRegExp filter)
        Adds all the variables from the other Variables object (overwrites any existing ones).
        Parameters:
        other - the Variables to copy
        filter - the regular expression that the variable names must match, null to ignore
      • toString

        public String toString()
        Simply returns the internal hashtable of variable/value pairs.
        Overrides:
        toString in class Object
        Returns:
        the stored variables