Class AddEnvironment

java.lang.Object
uk.ac.starlink.ttools.task.AddEnvironment
All Implemented Interfaces:
uk.ac.starlink.task.Environment

public class AddEnvironment extends Object implements uk.ac.starlink.task.Environment
Environment implementation which wraps a base environment instance and adds some extra entries as specified by a given map.

Note this does not work perfectly, because of bad design of the Environment class. The acquireValue method can end up passing an instance of the wrapped environment to a parameter, which means that subequent environment accesses made under the control of that parameter will not pick up entries added to this environment. A redesign of the Environment class is the only good way out of this. Until then you have to hack round it by explicitly calling acquireValue from this class on dependent variables before it gets done under control of the variable they depend on.

Since:
2013
Author:
Mark Taylor
  • Constructor Details

    • AddEnvironment

      public AddEnvironment(uk.ac.starlink.task.Environment baseEnv, Map<String,String> addMap)
      Constructor.
      Parameters:
      baseEnv - base environment
      addMap - addional key-value pairs to add to this environment
  • Method Details

    • acquireValue

      public void acquireValue(uk.ac.starlink.task.Parameter<?> par) throws uk.ac.starlink.task.TaskException
      Specified by:
      acquireValue in interface uk.ac.starlink.task.Environment
      Throws:
      uk.ac.starlink.task.TaskException
    • clearValue

      public void clearValue(uk.ac.starlink.task.Parameter<?> par)
      Specified by:
      clearValue in interface uk.ac.starlink.task.Environment
    • getNames

      public String[] getNames()
      Specified by:
      getNames in interface uk.ac.starlink.task.Environment
    • getOutputStream

      public PrintStream getOutputStream()
      Specified by:
      getOutputStream in interface uk.ac.starlink.task.Environment
    • getErrorStream

      public PrintStream getErrorStream()
      Specified by:
      getErrorStream in interface uk.ac.starlink.task.Environment
    • createAddEnvironment

      public static AddEnvironment createAddEnvironment(uk.ac.starlink.task.Environment baseEnv, Map<String,String> addMap)
      Returns an AddEnvironment based on a supplied base environment and a map of key-value pairs. If the supplied base environment is a TableEnvironment instance, the returned value will be as well.
      Parameters:
      baseEnv - base environment
      addMap - addional key-value pairs to add to this environment
      Returns:
      Environment or TableEnvironment instance with additional entries