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

ch.obermuhlner.scriptengine.jshell.VariablesTransfer Maven / Gradle / Ivy

The newest version!
package ch.obermuhlner.scriptengine.jshell;

import java.util.Map;

/**
 * Utility to transfer variables in and out of a JShell evaluation.
 */
public class VariablesTransfer {
    private static final ThreadLocal> threadLocalVariables = new ThreadLocal<>();

    private VariablesTransfer() {
        // empty
    }

    /**
     * Sets all variables for an evaluation.
     *
     * @param variables the name/value pairs
     */
    public static void setVariables(Map variables) {
        threadLocalVariables.set(variables);
    }

    /**
     * Returns the variable value for the specified name.
     *
     * @param name the name of the variable
     * @return the value of the variable, or null if not defined
     */
    public static Object getVariableValue(String name) {
        return threadLocalVariables.get().get(name);
    }

    /**
     * Sets the variable value for the specified name.
     *
     * @param name the name of the variable
     * @param value the value of the variable
     */
    public static void setVariableValue(String name, Object value) {
        threadLocalVariables.get().put(name, value);
    }

    /**
     * Clears all variables.
     */
    public static void clear() {
        threadLocalVariables.get().clear();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy