All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.snapscript.common.command.MapEnvironment Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.common.command;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class MapEnvironment implements Environment {

   private final Map variables;

   public MapEnvironment(Map variables) {
      this.variables = variables;
   }

   @Override
   public ProcessBuilder createProcess(String... command) {
      return createProcess(Arrays.asList(command));
   }

   @Override
   public ProcessBuilder createProcess(List command) {
      ProcessBuilder builder = new ProcessBuilder(command);

      if (!variables.isEmpty()) {
         Set names = variables.keySet();

         for (String name : names) {
            String value = variables.get(name);
            builder.environment().put(name, value);
         }
      }
      return builder;
   }
   
   @Override
   public String toString() {
      return String.valueOf(variables);
   }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy