Package weka.core

Class Environment

  • All Implemented Interfaces:
    RevisionHandler
    Direct Known Subclasses:
    JobEnvironment

    public class Environment
    extends java.lang.Object
    implements RevisionHandler
    This class encapsulates a map of all environment and java system properties. There are methods for adding and removing variables to this Environment object as well as to the system wide global environment. There is also a method for replacing key names (enclosed by ${}) with their associated value in Strings.
    Version:
    $Revision: 13893 $
    Author:
    Mark Hall (mhall{[at]}pentaho{[dot]}com)
    • Constructor Summary

      Constructors 
      Constructor Description
      Environment()
      Constructs a new Environment object with all environment variables and java properties set.
      Environment​(Environment other)
      Constructor that makes a new Environment object containing all the entries in the supplied one
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addVariable​(java.lang.String key, java.lang.String value)
      Add a variable to the internal map of this properties object.
      void addVariableSystemWide​(java.lang.String key, java.lang.String value)
      Add a a variable to the internal map of this properties object and to the global system-wide environment;
      static boolean containsEnvVariables​(java.lang.String source)
      Tests for the presence of environment variables.
      java.lang.String getRevision()
      Returns the revision string.
      static Environment getSystemWide()
      Get the singleton system-wide (visible to every class in the running VM) set of environment variables.
      java.util.Set<java.lang.String> getVariableNames()
      Get the names of the variables (keys) stored in the internal map.
      java.lang.String getVariableValue​(java.lang.String key)
      Get the value for a particular variable.
      static void main​(java.lang.String[] args)
      Main method for testing this class.
      void removeVariable​(java.lang.String key)
      Remove a named variable from the map.
      java.lang.String substitute​(java.lang.String source)
      Substitute a variable names for their values in the given string.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Environment

        public Environment()
        Constructs a new Environment object with all environment variables and java properties set.
      • Environment

        public Environment​(Environment other)
        Constructor that makes a new Environment object containing all the entries in the supplied one
        Parameters:
        other - the Environment object to copy to this one
    • Method Detail

      • getSystemWide

        public static Environment getSystemWide()
        Get the singleton system-wide (visible to every class in the running VM) set of environment variables.
        Returns:
        the system-wide set of environment variables.
      • containsEnvVariables

        public static boolean containsEnvVariables​(java.lang.String source)
        Tests for the presence of environment variables.
        Parameters:
        source - the string to test
        Returns:
        true if the argument contains one or more environment variables
      • substitute

        public java.lang.String substitute​(java.lang.String source)
                                    throws java.lang.Exception
        Substitute a variable names for their values in the given string.
        Parameters:
        source - the source string to replace variables in
        Returns:
        a String with all variable names replaced with their values
        Throws:
        java.lang.Exception - if an unknown variable name is encountered
      • addVariable

        public void addVariable​(java.lang.String key,
                                java.lang.String value)
        Add a variable to the internal map of this properties object.
        Parameters:
        key - the name of the variable
        value - its value
      • addVariableSystemWide

        public void addVariableSystemWide​(java.lang.String key,
                                          java.lang.String value)
        Add a a variable to the internal map of this properties object and to the global system-wide environment;
        Parameters:
        key - the name of the variable
        value - its value
      • removeVariable

        public void removeVariable​(java.lang.String key)
        Remove a named variable from the map.
        Parameters:
        key - the name of the varaible to remove.
      • getVariableNames

        public java.util.Set<java.lang.String> getVariableNames()
        Get the names of the variables (keys) stored in the internal map.
        Returns:
        a Set of variable names (keys)
      • getVariableValue

        public java.lang.String getVariableValue​(java.lang.String key)
        Get the value for a particular variable.
        Parameters:
        key - the name of the variable to get
        Returns:
        the associated value or null if this variable is not in the internal map
      • main

        public static void main​(java.lang.String[] args)
        Main method for testing this class.
        Parameters:
        args - a list of strings to replace variables in (e.g. "\${os.name} "\${java.version}")
      • getRevision

        public java.lang.String getRevision()
        Returns the revision string.
        Specified by:
        getRevision in interface RevisionHandler
        Returns:
        the revision