Skip to content

Commit d7a8f01

Browse files
author
Rúben André Barreiro
committed
NOT Gate added
1 parent f7108fb commit d7a8f01

File tree

1 file changed

+92
-0
lines changed
  • src/main/java/org/quisl/framework/java/instructions/gates/classical/single

1 file changed

+92
-0
lines changed
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
package org.quisl.framework.java.instructions.gates.classical.single;
2+
3+
import org.quisl.framework.java.instructions.gates.classical.ClassicalGate;
4+
5+
public class NOTGate extends ClassicalGate {
6+
7+
8+
private final Boolean input;
9+
10+
private Boolean output;
11+
12+
13+
public NOTGate(Boolean input) {
14+
15+
super(1, 1, "NOTGate");
16+
17+
this.input = input;
18+
19+
this.output = !this.input;
20+
21+
}
22+
23+
public NOTGate(Integer input) throws Exception {
24+
25+
super(1, 1, "NOTGate");
26+
27+
if(input == 1) {
28+
29+
this.input = true;
30+
31+
}
32+
else if(input == 0) {
33+
34+
this.input = false;
35+
36+
}
37+
else {
38+
39+
throw new Exception();
40+
41+
}
42+
43+
}
44+
45+
46+
public Boolean getInput() {
47+
48+
return this.input;
49+
50+
}
51+
52+
public Boolean getOutput() {
53+
54+
return this.output;
55+
56+
}
57+
58+
@Override
59+
public void applyGate() {
60+
61+
this.output = !this.input;
62+
63+
}
64+
65+
66+
public static String[] getLabelsNOTTruthTable() {
67+
68+
return new String[] { "Input", "Output" };
69+
70+
}
71+
72+
public static Integer[][] getIntegerNOTTruthTable() {
73+
74+
return new Integer[][]
75+
{
76+
new Integer[] { 0 , 1 },
77+
new Integer[] { 1 , 0 }
78+
};
79+
80+
}
81+
82+
public static Boolean[][] getBooleanNOTTruthTable() {
83+
84+
return new Boolean[][]
85+
{
86+
new Boolean[] { false , true },
87+
new Boolean[] { true , false }
88+
};
89+
90+
}
91+
92+
}

0 commit comments

Comments
 (0)