minor changes

This commit is contained in:
hneemann 2016-03-19 23:08:58 +01:00
parent da0646b53f
commit 289b15bac9
10 changed files with 20 additions and 37 deletions

View File

@ -22,8 +22,9 @@ public class ObservableValue extends Value {
observers = new ArrayList<>(); observers = new ArrayList<>();
} }
public void addObserver(Observer observer) { public ObservableValue addObserver(Observer observer) {
observers.add(observer); observers.add(observer);
return this;
} }
public void removeObserver(Observer observer) { public void removeObserver(Observer observer) {

View File

@ -53,12 +53,9 @@ public class Add extends Node implements Part {
@Override @Override
public void setInputs(ObservableValue... inputs) throws BitsException { public void setInputs(ObservableValue... inputs) throws BitsException {
a = inputs[0]; a = inputs[0].addObserver(this);
a.addObserver(this); b = inputs[1].addObserver(this);
b = inputs[1]; c_in = inputs[2].addObserver(this);
b.addObserver(this);
c_in = inputs[2];
c_in.addObserver(this);
if (a.getBits() != bits) if (a.getBits() != bits)
throw new BitsException("wrongBitCount", a); throw new BitsException("wrongBitCount", a);

View File

@ -39,10 +39,8 @@ public class Mul extends Node implements Part {
@Override @Override
public void setInputs(ObservableValue... inputs) throws NodeException { public void setInputs(ObservableValue... inputs) throws NodeException {
a = inputs[0]; a = inputs[0].addObserver(this);
a.addObserver(this); b = inputs[1].addObserver(this);
b = inputs[1];
b.addObserver(this);
} }
@Override @Override

View File

@ -38,8 +38,7 @@ public class Not extends Node implements Part {
@Override @Override
public void setInputs(ObservableValue... inputs) throws NodeException { public void setInputs(ObservableValue... inputs) throws NodeException {
input = inputs[0]; input = inputs[0].addObserver(this);
input.addObserver(this);
} }
@Override @Override

View File

@ -38,10 +38,8 @@ public class XOr extends Node implements Part {
@Override @Override
public void setInputs(ObservableValue... inputs) throws BitsException { public void setInputs(ObservableValue... inputs) throws BitsException {
a = inputs[0]; a = inputs[0].addObserver(this);
a.addObserver(this); b = inputs[1].addObserver(this);
b = inputs[1];
b.addObserver(this);
if (a.getBits() != bits) if (a.getBits() != bits)
throw new BitsException("wrongBitCount", a); throw new BitsException("wrongBitCount", a);

View File

@ -45,10 +45,8 @@ public class D_FF extends Node implements Part {
@Override @Override
public void setInputs(ObservableValue... inputs) throws BitsException { public void setInputs(ObservableValue... inputs) throws BitsException {
dVal = inputs[0]; dVal = inputs[0].addObserver(this);
dVal.addObserver(this); clockVal = inputs[1].addObserver(this);
clockVal = inputs[1];
clockVal.addObserver(this);
if (dVal.getBits() != bits) if (dVal.getBits() != bits)
throw new BitsException("wrongBitCount", dVal); throw new BitsException("wrongBitCount", dVal);

View File

@ -49,12 +49,9 @@ public class JK_FF extends Node implements Part {
@Override @Override
public void setInputs(ObservableValue... inputs) throws BitsException { public void setInputs(ObservableValue... inputs) throws BitsException {
jVal = inputs[0]; jVal = inputs[0].addObserver(this);
jVal.addObserver(this); clockVal = inputs[1].addObserver(this);
clockVal = inputs[1]; kVal = inputs[2].addObserver(this);
clockVal.addObserver(this);
kVal = inputs[2];
kVal.addObserver(this);
if (jVal.getBits() != 1) if (jVal.getBits() != 1)
throw new BitsException("wrongBitCount", jVal); throw new BitsException("wrongBitCount", jVal);

View File

@ -48,12 +48,9 @@ public class RS_FF extends Node implements Part {
@Override @Override
public void setInputs(ObservableValue... inputs) throws BitsException { public void setInputs(ObservableValue... inputs) throws BitsException {
jVal = inputs[0]; jVal = inputs[0].addObserver(this);
jVal.addObserver(this); clockVal = inputs[1].addObserver(this);
clockVal = inputs[1]; kVal = inputs[2].addObserver(this);
clockVal.addObserver(this);
kVal = inputs[2];
kVal.addObserver(this);
if (jVal.getBits() != 1) if (jVal.getBits() != 1)
throw new BitsException("wrongBitCount", jVal); throw new BitsException("wrongBitCount", jVal);

View File

@ -42,8 +42,7 @@ public class T_FF extends Node implements Part {
@Override @Override
public void setInputs(ObservableValue... inputs) throws BitsException { public void setInputs(ObservableValue... inputs) throws BitsException {
clockVal = inputs[0]; clockVal = inputs[0].addObserver(this);
clockVal.addObserver(this);
if (clockVal.getBits() != 1) if (clockVal.getBits() != 1)
throw new BitsException("carryIsABit", clockVal); throw new BitsException("carryIsABit", clockVal);

View File

@ -42,8 +42,7 @@ public class Delay extends Node implements Part {
@Override @Override
public void setInputs(ObservableValue... inputs) throws NodeException { public void setInputs(ObservableValue... inputs) throws NodeException {
input = inputs[0]; input = inputs[0].addObserver(this);
input.addObserver(this);
if (input.getBits() != bits) if (input.getBits() != bits)
throw new BitsException("wrongBitCountInDelay", input, output); throw new BitsException("wrongBitCountInDelay", input, output);