Commit ca7e943c authored by jm15g21's avatar jm15g21
Browse files


parent 1adc9e7d
......@@ -41,23 +41,19 @@ public class OperationDecr implements IOperation{
//It could be static I guess, but we can have multiple interpreters running at once if we ever
//needed that for some reason.
Hashtable<String, Integer> variableStoreReference = master.getVariableStore();
//Store the existing value
int existingValue = 0;
//Check if the variable already exists in the variable store
if (variableStoreReference.containsKey(instruction.getArguments()[0]))
//Decrement the variable with the name passed in as argument by 1.
int integerObjectReference = variableStoreReference.get(instruction.getArguments()[0]);
if(integerObjectReference == 1) {
//Remove the reference to it, since it is now 0
else {
//Put it back in, referencing doesn't work on Integer class?
variableStoreReference.replace(instruction.getArguments()[0], integerObjectReference - 1);
existingValue = variableStoreReference.get(instruction.getArguments()[0]);
//Check for negatives
if(existingValue == 0)
throw new NegativeVariableException("Variable " + instruction.getArguments()[0] + " decremented without existing.");
//Change the value
master.modifyVariable(instruction.getArguments()[0], existingValue - 1);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment