LogicGates/eu.heili/LogicGate.java
2020-04-13 11:23:57 +02:00

35 lines
843 B
Java

import java.util.ArrayList;
import java.util.Arrays;
public abstract class LogicGate {
private final ArrayList<DigitalInput> inputs = new ArrayList<>();
/**
* validate gate output.
* @return validated output
*/
public abstract boolean getOutput();
public LogicGate(int inputnr) {
for (int i = 0; i < inputnr; i++) {
inputs.add(new DigitalInput()); // generate new objects for new inputs
}
}
public LogicGate(boolean... inputvals) {
for (boolean i:inputvals) {
inputs.add(new DigitalInput(i));
}
}
public DigitalInput getInput(int nr) {
if (nr >= getInputNumber())
throw (new InputOutOfBoundsException());
return inputs.get(nr);
}
public int getInputNumber() {
return inputs.size();
}
}