b13dd2bc9a2b78633418e8b1e4bd6280dca4e59f
[Mograsim.git] / era.mi / src / era / mi / logic / components / gates / XorGate.java
1 package era.mi.logic.components.gates;
2
3 import java.util.Arrays;
4 import java.util.Collections;
5 import java.util.List;
6
7 import era.mi.logic.Util;
8 import era.mi.logic.components.BasicComponent;
9 import era.mi.logic.wires.WireArray;
10 import era.mi.logic.wires.WireArray.WireArrayInput;
11
12 public class XorGate extends BasicComponent
13 {
14         private WireArray a, b, out;
15         private WireArrayInput outI;
16         
17         public XorGate(int processTime, WireArray a, WireArray b, WireArray out)
18         {
19                 super(processTime);
20                 this.a = a;
21                 a.addObserver(this);
22                 this.b = b;
23                 b.addObserver(this);
24                 this.out = out;
25         }
26
27         protected void compute()
28         {
29                 outI.feedSignals(Util.xor(a.getValues(), b.getValues()));
30         }
31
32         public WireArray getA()
33         {
34                 return a;
35         }
36
37         public WireArray getB()
38         {
39                 return b;
40         }
41
42         public WireArray getOut()
43         {
44                 return out;
45         }
46         
47         @Override
48         public List<WireArray> getAllInputs()
49         {
50                 return Collections.unmodifiableList(Arrays.asList(a, b));
51         }
52
53         @Override
54         public List<WireArray> getAllOutputs()
55         {
56                 return Collections.unmodifiableList(Arrays.asList(out));
57         }
58 }