package easysm.stores;
import java.util.List;
import easysm.Constants;
import easysm.datatypes.Name;
import easysm.datatypes.Value;
import easysm.datatypes.information.StateTableInfo;
import easysm.datatypes.visualization.StateTableVis;
import easysm.factories.ListFactory;
/**
* @author FourCheeses Software Solutions
*/
public class StateTable extends Element
{
/**
* Required field to make serialization more robust. See documentation for
* technical details.
*/
private static final long serialVersionUID = 2352701157858635702L;
private List<StateObserver> usedSO;
private List<Row> rows;
private StateTableVis vis;
public StateTable(StateTableInfo stateTableInfo)
{
super(stateTableInfo);
initStateTable();
vis = new StateTableVis(this);
}
/*
*
* Properties
*
*/
public List<StateObserver> usedSO()
{
return usedSO;
}
public void changeUsedSO(List<StateObserver> newUsedSO)
{
if (newUsedSO != null) {
usedSO = newUsedSO;
} else {
usedSO = ListFactory.createList(StateObserver.class);
usedSO.add(StateObserver.FINAL);
}
changeRows(null);
}
public List<Row> rows()
{
return rows;
}
public void changeRows(List<Row> newRows)
{
rows = (newRows != null) ? newRows : ListFactory.createList(Row.class);
}
public StateTableVis vis()
{
return vis;
}
/*
*
* Operations called by Main
*
*/
public void defineState(Row row,
Name name)
{
if (name.equals(Constants.IMPOSSIBLE_NAME)) {
row.changeState(null);
return;
}
int finalSOIndex = -1;
for (int i = 0; i < usedSO.size(); ++i) {
if (usedSO.get(i).equals(StateObserver.FINAL)) {
finalSOIndex = i;
break;
}
}
if (finalSOIndex != -1 && finalSOIndex != usedSO.size()) {
Value trueValue = new Value(Constants.TRUE_REPR);
if (row.values().get(finalSOIndex).equals(trueValue)) {
row.changeState(new State(name, true));
return;
}
}
row.changeState(new State(name, false));
}
/*
*
* Public methods
*
*/
public void clear()
{
initStateTable();
}
/*
*
* Private methods
*
*/
private void initStateTable()
{
changeUsedSO(null);
}
}