/*
PseudoCode Interpreted Language (PCIL): Part of the algoviz@vt collection of algorithm visualizations.
Copyright (C) 2008 Brandon Malone, Frank Hadlock
This file is part of the PseudoCode Interpreted Language.
PseudoCode Interpreted Language is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
PseudoCode Interpreted Language is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Public License for more details.
You should have received a copy of the GNU General Public License along with
PseudoCode Interpreted Language. If not, see
.
*/
/*
* State.java
*
* Created on September 17, 2007, 9:45 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package dynamicmvc;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import syntacticanalysis.Function;
/**
*
* @author Compaq_Owner
*/
public class State implements Serializable {
private HashMap inputs;
private HashMap stateVariables;
/** Creates a new instance of State */
public State() {
inputs = new HashMap();
stateVariables = new HashMap();
}
public PrimitivePointer getPrimitive(int lineNumber) throws DynamicMVCException {
PrimitivePointer sp = PrimitiveFactory.create(PrimitiveStructure.pseudocodeTypeName(), "state");
for(String name : stateVariables.keySet()) {
PrimitivePointer p = stateVariables.get(name);
((PrimitiveStructure)sp.dereference()).set(name, p);
}
PrimitivePointer ln = PrimitiveFactory.create(PrimitiveInteger.pseudocodeTypeName(), "line");
((PrimitiveInteger)ln.dereference()).setValue(lineNumber);
((PrimitiveStructure)sp.dereference()).set(ln.getName(), ln);
((PrimitiveStructure)sp.dereference()).setMyState(this);
return sp;
}
public PrimitivePointer getPrimitive(int lineNumber, ArrayList functions) throws DynamicMVCException {
PrimitivePointer sp = getPrimitive(lineNumber);
((PrimitiveStructure)sp.dereference()).setFunctions(functions);
return sp;
}
public Collection getVariables() {
Collection variables = new ArrayList();
for(PrimitivePointer i : inputs.values()) {
variables.add(i);
}
for(PrimitivePointer i : stateVariables.values()) {
variables.add(i);
}
return variables;
}
//
public PrimitivePointer getInput(String name) {
return inputs.get(name);
}
public void setInput(String name, PrimitivePointer input) {
inputs.put(name, input);
}
public Collection getInputs() {
return inputs.values();
}
public void setInputs(HashMap inputs) {
this.inputs = inputs;
}
public void clearInputs() {
inputs.clear();
}
//
//
public Collection getStateVariables() {
return stateVariables.values();
}
public void setStateVariables(HashMap stateVariables) {
this.stateVariables = stateVariables;
}
public PrimitivePointer getStateVariable(String name) {
return stateVariables.get(name);
}
public void setStateVariable(String name, PrimitivePointer stateVariable) {
//PrimitivePointer sv = stateVariable.copy();
stateVariable.setName(name);
stateVariables.put(name, stateVariable);
}
public void removeStateVariable(String name) {
stateVariables.remove(name);
}
public void clearStateVariables() {
stateVariables.clear();
}
//
}