28 lines
707 B
Java
28 lines
707 B
Java
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();
|
|
}
|
|
}
|