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