added demux; added getAllInputs() and getAllOutputs() for all components
[Mograsim.git] / era.mi / src / era / mi / logic / components / gates / AndGate.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 AndGate extends BasicComponent
13 {
14         private WireArray a, b, out;
15         private WireArrayInput outI;
16         
17         public AndGate(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                 outI = out.createInput();
26         }
27
28         protected void compute()
29         {
30                 outI.feedSignals(Util.and(a.getValues(), b.getValues()));
31         }
32
33         public WireArray getA()
34         {
35                 return a;
36         }
37
38         public WireArray getB()
39         {
40                 return b;
41         }
42
43         public WireArray getOut()
44         {
45                 return out;
46         }
47
48         @Override
49         public List<WireArray> getAllInputs()
50         {
51                 return Collections.unmodifiableList(Arrays.asList(a, b));
52         }
53
54         @Override
55         public List<WireArray> getAllOutputs()
56         {
57                 return Collections.unmodifiableList(Arrays.asList(out));
58         }
59 }