Skip to content

Commit

Permalink
Setting up an environment
Browse files Browse the repository at this point in the history
  • Loading branch information
maria77102 committed May 23, 2024
1 parent 6104ee2 commit 092e69b
Showing 1 changed file with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.regnosys.rosetta.interpreternew.values;

import java.util.HashMap;
import java.util.Map;

public class RosettaInterpreterEnvironment {
private Map<String, RosettaInterpreterBaseValue> environment;

public RosettaInterpreterEnvironment() {
this.setEnvironment(new HashMap<>());
}

public RosettaInterpreterEnvironment(Map<String, RosettaInterpreterBaseValue> el) {
this.setEnvironment(el);
}

public Map<String, RosettaInterpreterBaseValue> getEnvironment() {
return environment;
}

public void setEnvironment(Map<String, RosettaInterpreterBaseValue> env) {
this.environment = env;
}

/**
* Find a value, by name, in the environment.
*
* @param name - name of the variable you search for
* @return - the value iff variable exists in environment
* error otherwise
*/
public RosettaInterpreterBaseValue findValue(String name) {
if (environment.containsKey(name)) {
return environment.get(name);
}
else {
return new RosettaInterpreterErrorValue(
new RosettaInterpreterError(
"no such variable in the environment"));
}

}

/**
* Add a variable and its value to the environment.
*
* @param name - name of the variable
* @param val - value of the variable
*/
public void addValue(String name,
RosettaInterpreterBaseValue val) {

if (environment.containsKey(name)) {
//update env
environment.replace(name, val);
}
else {
environment.put(name, val);
}

}


}

0 comments on commit 092e69b

Please sign in to comment.