LogicGates/eu.heili/LogicGate.java

28 lines
707 B
Java
Raw Normal View History

2020-04-13 09:14:15 +00:00
import java.util.ArrayList;
import java.util.Arrays;
public abstract class LogicGate {
private final ArrayList<DigitalInput> inputs = new ArrayList<>();
public LogicGate(int inputnr) {
for(int i=0; i < inputnr; i++){
inputs.add(new DigitalInput()); // generate new objects for new inputs
}
}
public LogicGate(DigitalInput... inputvals) {
inputs.addAll(Arrays.asList(inputvals));
}
public abstract boolean getOutput();
public DigitalInput getInput(int nr) {
// todo validate existance of nr --> indexoutofbounds exception
return inputs.get(nr);
}
public int getInputNumber(){
return inputs.size();
}
}