- @Override
- public void setAtomicHighLevelState(String stateID, Object newState)
- {
- switch (stateID)
- {
- case "q":
- if (wireQ != null)
- {
- // TODO force this to happen without any Timeline updates in the meantime.
- // Maybe make it a requirement of setHighLevelState that the Timeline is "halted" during a call?
- Bit newStateCasted = (Bit) newState;
- BitVector newStateVector = BitVector.of(newStateCasted);
- if (wireQ.hasLogicModelBinding())
- wireQ.forceWireValues(newStateVector);
- // We set both wires because then both outputs go to their correct state at the same time, and to avoid problems when not
- // both
- // inputs are 1
- if (wire_Q.hasLogicModelBinding())
- wire_Q.forceWireValues(newStateVector.not());
- }
- break;
- default:
- // should not happen because we tell SubmodelComponent to only allow these state IDs.
- throw new IllegalStateException("Illegal atomic state ID: " + stateID);
- }
- }
-
- @Override
- public Object getAtomicHighLevelState(String stateID)
- {
- switch (stateID)
- {
- case "q":
- if (wireQ.hasLogicModelBinding())
- return wireQ.getWireValues().getBit(0);
- return null;
- default:
- // should not happen because we tell SubmodelComponent to only allow these state IDs.
- throw new IllegalStateException("Illegal atomic state ID: " + stateID);
- }
+ StandardHighLevelStateHandler highLevelStateHandler = new StandardHighLevelStateHandler(this);
+ highLevelStateHandler.addAtomicHighLevelState("q", WireForcingAtomicHighLevelStateHandler::new).set(Arrays.asList(wireQ),
+ Arrays.asList(wire_Q));
+ setHighLevelStateHandler(highLevelStateHandler);