Advertisement
Guest User

Untitled

a guest
Mar 17th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.List;
  3. import java.util.Map;
  4. import java.util.Set;
  5.  
  6. public class Circuit {
  7. private Map<String, CircuitComponent> components;
  8.  
  9. Circuit(){
  10.  
  11. components= new HashMap<String,CircuitComponent>();
  12. }
  13.  
  14. public void addComponent(String name, CircuitComponent component) throws RuntimeException{
  15.  
  16. this.components.put(name, component);
  17.  
  18. }
  19.  
  20. public CircuitComponent getComponent(String name) {
  21.  
  22. if(components.containsKey(name)) {
  23. return (components.get(name));}
  24.  
  25. else {return null;}
  26.  
  27. }
  28.  
  29. public Set<String> componentNames() {
  30. return components.keySet();
  31. }
  32.  
  33. public void tick() {
  34.  
  35.  
  36. for (CircuitComponent value : components.values()) {
  37. value.updateState();
  38.  
  39. }
  40.  
  41. for (CircuitComponent value : components.values()) {
  42. value.propagateStateChange();
  43.  
  44. }
  45.  
  46. }
  47.  
  48. public Circuit(List<String> lines) {
  49. for(int i=0; i<lines.size(); i++) {
  50. String s = lines.get(i);
  51. String [] splitted = s.split(" ");
  52.  
  53. if(splitted[1].equals("AND"))
  54. CircuitComponent c= new AndGate();
  55.  
  56.  
  57. addComponent(splitted[0],)
  58. }
  59.  
  60.  
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement