added some comments

This commit is contained in:
hneemann 2018-07-17 07:47:44 +02:00
parent 6a7282e52e
commit b6fa1f6c0a
2 changed files with 17 additions and 12 deletions

View File

@ -89,29 +89,29 @@ public class Switch implements Element, NodeInterface {
final CommonBusValue in2 = (CommonBusValue) input2; final CommonBusValue in2 = (CommonBusValue) input2;
ObservableValue constant = in1.searchConstant(); ObservableValue constant = in1.searchConstant();
if (constant != null) if (constant != null)
switchModel = new SimpleSwitch(constant, output2); switchModel = new UniDirectionalSwitch(constant, output2);
else { else {
constant = in2.searchConstant(); constant = in2.searchConstant();
if (constant != null) if (constant != null)
switchModel = new SimpleSwitch(constant, output1); switchModel = new UniDirectionalSwitch(constant, output1);
else else
switchModel = new RealSwitch(in1, in2); switchModel = new RealSwitch(in1, in2);
} }
} else } else
switchModel = new SimpleSwitch(input1, output2); switchModel = new UniDirectionalSwitch(input1, output2);
} else { } else {
if (input2 instanceof CommonBusValue) { if (input2 instanceof CommonBusValue) {
switchModel = new SimpleSwitch(input2, output1); switchModel = new UniDirectionalSwitch(input2, output1);
} else { } else {
throw new NodeException(Lang.get("err_switchHasNoNet"), output1, output2); throw new NodeException(Lang.get("err_switchHasNoNet"), output1, output2);
} }
} }
break; break;
case FROM1TO2: case FROM1TO2:
switchModel = new SimpleSwitch(input1, output2); switchModel = new UniDirectionalSwitch(input1, output2);
break; break;
case FROM2TO1: case FROM2TO1:
switchModel = new SimpleSwitch(input2, output1); switchModel = new UniDirectionalSwitch(input2, output1);
break; break;
} }
} }
@ -126,7 +126,7 @@ public class Switch implements Element, NodeInterface {
} }
@Override @Override
public void init(Model model) throws NodeException { public void init(Model model) {
switchModel.setModel(model); switchModel.setModel(model);
switchModel.setClosed(closed); switchModel.setClosed(closed);
hasChanged(); hasChanged();
@ -179,12 +179,17 @@ public class Switch implements Element, NodeInterface {
void setModel(Model model); void setModel(Model model);
} }
private static final class SimpleSwitch implements SwitchModel { /**
* A simple unidirectional switch.
* Works like a driver: When the switch is closed, the signal value at the input
* is forwarded to the output. When the switch is open, the output is set to HighZ.
*/
private static final class UniDirectionalSwitch implements SwitchModel {
private final ObservableValue input; private final ObservableValue input;
private final ObservableValue output; private final ObservableValue output;
private boolean closed; private boolean closed;
SimpleSwitch(ObservableValue input, ObservableValue output) { UniDirectionalSwitch(ObservableValue input, ObservableValue output) {
this.input = input; this.input = input;
this.output = output; this.output = output;
} }
@ -209,7 +214,7 @@ public class Switch implements Element, NodeInterface {
} }
/** /**
* represents a switch * Represents a real bidirectional switch.
*/ */
public static final class RealSwitch implements SwitchModel { public static final class RealSwitch implements SwitchModel {
private final CommonBusValue input1; private final CommonBusValue input1;

View File

@ -15,8 +15,8 @@ import java.util.HashSet;
/** /**
* Checks if a temporary burn condition is still present after the step is completed. * Checks if a temporary burn condition is still present after the step is completed.
* If so an exception is thrown. * If so, an exception is thrown.
* Handles also the reconfiguration of the nets if a switches has changed. * Handles also the reconfiguration of the nets if a switch has changed.
*/ */
public final class BusModelStateObserver implements ModelStateObserverTyped { public final class BusModelStateObserver implements ModelStateObserverTyped {
private final ArrayList<AbstractBusHandler> busList; private final ArrayList<AbstractBusHandler> busList;