Commit 1bcba990 authored by jm15g21's avatar jm15g21
Browse files

Update OperationIncr.java

parent 8bab7c0f
......@@ -39,18 +39,14 @@ public class OperationIncr 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]))
{
//Incremember the variable with the name passed in as argument by 1.
Integer integerObjectReference = variableStoreReference.get(instruction.getArguments()[0]);
integerObjectReference ++;
//Put it back in, referencing doesn't work on Integer class?
variableStoreReference.replace(instruction.getArguments()[0], integerObjectReference);
}
else
{
variableStoreReference.put(instruction.getArguments()[0], new Integer(1));
existingValue = variableStoreReference.get(instruction.getArguments()[0]);
}
//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