1   /**
2    * 183.592 Programmierpraxis TU Wien WS2014/15 H.Moritsch
3    * Gatter-Klasse
4    * Der Wert am Ausgang wird in value gespeichert
5    */
6   public class Gate {
7   
8       private boolean value;          // Wert am Ausgang
9       private String operation;       // Gatter-Operation
10      private Gate input1;            // Eingang 1
11      private Gate input2;            // Eingang 2 (falls vorhanden)
12  
13      // Gatter mit zwei Eingängen
14      public Gate(Gate input1, String operation, Gate input2) {
15          this.input1 = input1;
16          this.input2 = input2;
17          this.operation = operation;
18      }
19  
20      // Gatter mit einem Eingang
21      public Gate(String operation, Gate input) {
22          this.input1 = input;
23          this.operation = operation;
24      }
25  
26      public Gate() {
27          this.operation = "";        // keine Operation definiert
28      }
29  
30      public boolean getValue() {
31          return value;
32      }
33  
34      public void setValue(boolean value) {
35          this.value = value;
36      }
37  
38      // Durchführung der Gatter-Operation
39      public void operate() {
40          if (! operation.equals("")) {
41  
42              if (operation.equals("AND")) {
43                  value = input1.getValue() && input2.getValue(); // AND
44              }
45              else if (operation.equals("OR")) {
46                  value = input1.getValue() || input2.getValue(); // OR
47              }
48              else if (operation.equals("NOT")) {                 // NOT
49                  value = ! input1.getValue();
50              }
51          }
52      }
53  
54  }
55