import java.util.ArrayList; import java.util.Arrays; public abstract class LogicGate { private final ArrayList 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)); } /** * validate gate output. * * @return validated output */ public abstract boolean getOutput(); public DigitalInput getInput(int nr) { if (nr >= getInputNumber()) throw (new InputOutOfBoundsException()); return inputs.get(nr); } public int getInputNumber() { return inputs.size(); } public void addInput(DigitalInput in) { inputs.add(in); } }