Node.java 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package classes;
  2. import java.util.ArrayList;
  3. import java.util.UUID;
  4. /**
  5. * The class "CpsNode" represents empty Objects in the system. They are just
  6. * nodes between Objects
  7. *
  8. * @author Gruppe14
  9. *
  10. */
  11. public class Node extends AbstractCanvasObject {
  12. private String uniqueID;
  13. /**
  14. * Create a new node in the system with an user-defined name.
  15. *
  16. * @param objName
  17. * String
  18. */
  19. public Node(String objName) {
  20. super(objName);
  21. this.setConnections(new ArrayList<Edge>());
  22. this.setImage("/Images/node.png");
  23. this.setSav("CVS");
  24. this.setId(IdCounter.nextId());
  25. this.uniqueID = "Node " + UUID.randomUUID();
  26. }
  27. public Node(Node node){
  28. super(node);
  29. this.uniqueID = "Node " + UUID.randomUUID();
  30. }
  31. public String toString(){
  32. return "Node ID:" + super.id;
  33. }
  34. @Override
  35. public AbstractCanvasObject makeCopy() {
  36. return new Node(this);
  37. }
  38. public String getUniqueID() {
  39. if(this.uniqueID == null)
  40. this.uniqueID = "Node "+UUID.randomUUID().toString();
  41. return uniqueID;
  42. }
  43. public ArrayList<String> getAllConnectedHolons(ArrayList<AbstractCanvasObject> visited) {
  44. ArrayList<String> conns = new ArrayList<String>();
  45. visited.add(this);
  46. for(Edge e : this.connections) {
  47. AbstractCanvasObject a = e.getA();
  48. AbstractCanvasObject b = e.getB();
  49. if(b.equals(this) && !visited.contains(a)) {
  50. if(a instanceof HolonObject) {
  51. conns.add(((HolonObject) a).holon.getUniqueID());
  52. } else if(a instanceof HolonSwitch) {
  53. conns.addAll(((HolonSwitch)a).getAllConnectedHolons(visited));
  54. } else if(a instanceof Node) {
  55. conns.addAll(((Node) a).getAllConnectedHolons(visited));
  56. } else if(a instanceof GroupNode) {
  57. conns.addAll(((GroupNode) a).getAllConnectedHolons(visited));
  58. }
  59. visited.add(a);
  60. } else if(a.equals(this) && !visited.contains(b)) {
  61. if(b instanceof HolonObject) {
  62. conns.add(((HolonObject) b).holon.getUniqueID());
  63. } else if(b instanceof HolonSwitch) {
  64. conns.addAll(((HolonSwitch)b).getAllConnectedHolons(visited));
  65. } else if(b instanceof Node) {
  66. conns.addAll(((Node) b).getAllConnectedHolons(visited));
  67. } else if(b instanceof GroupNode) {
  68. conns.addAll(((GroupNode) b).getAllConnectedHolons(visited));
  69. }
  70. visited.add(b);
  71. }
  72. }
  73. return conns;
  74. }
  75. }