package easysm.stores;
import java.util.List;
import java.util.Set;
import easysm.datatypes.information.StateObserverInfo;
import easysm.datatypes.information.StateObserversInfo;
import easysm.datatypes.visualization.StateObserverVis;
import easysm.datatypes.visualization.StateObserversVis;
import easysm.factories.ListFactory;
import easysm.factories.SetFactory;
/**
* @author FourCheeses Software Solutions
*/
public class StateObservers extends Element
{
/**
* Required field to make serialization more robust. See documentation for
* technical details.
*/
private static final long serialVersionUID = -3286489253250401700L;
private List<StateObserver> soList = ListFactory.createList(StateObserver.class);
public StateObservers(StateObserversInfo soInfo)
{
super(soInfo);
initSOList();
}
/*
*
* Properties
*
*/
public List<StateObserver> soList()
{
return soList;
}
public StateObserversVis vis()
{
Set<StateObserverVis> soVis = SetFactory.createSet(StateObserverVis.class);
for (StateObserver so : soList) {
soVis.add(so.vis());
}
return new StateObserversVis(soVis, this);
}
/*
*
* Operations called by UpdateStateObservers (via Main)
*
*/
public void addStateObserver(StateObserver so)
{
soList.add(so);
}
public void addStateObservers(Set<StateObserver> soSet)
{
soList.addAll(soSet);
}
public void deleteStateObserver(StateObserver so)
{
soList.remove(so);
}
public void updateStateObserver(StateObserver so,
StateObserverInfo newSoInfo)
{
so.changeName(newSoInfo.name());
so.changeType(newSoInfo.type());
so.changeInvariant(newSoInfo.invariant());
}
/*
*
* Public methods
*
*/
public void clear()
{
initSOList();
}
/*
*
* Private methods
*
*/
private void initSOList()
{
soList.clear();
// Adds default "final" state observer
addStateObserver(StateObserver.FINAL);
// Clears "final" state observer invariant
StateObserver.FINAL.changeInvariant(null);
}
}