-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6104ee2
commit 092e69b
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...c/main/java/com/regnosys/rosetta/interpreternew/values/RosettaInterpreterEnvironment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} | ||
|
||
|
||
} |