1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package classes;
- import java.util.ArrayList;
- import java.util.UUID;
- /**
- * The class "CpsNode" represents empty Objects in the system. They are just
- * nodes between Objects
- *
- * @author Gruppe14
- *
- */
- public class Node extends AbstractCanvasObject {
-
- private String uniqueID;
-
- /**
- * Create a new node in the system with an user-defined name.
- *
- * @param objName
- * String
- */
- public Node(String objName) {
- super(objName);
- this.setConnections(new ArrayList<Edge>());
- this.setImage("/Images/node.png");
- this.setSav("CVS");
- this.setId(IdCounter.nextId());
- this.uniqueID = "Node " + UUID.randomUUID();
- }
-
- public Node(Node node){
- super(node);
- this.uniqueID = "Node " + UUID.randomUUID();
- }
-
- public String toString(){
- return "Node ID:" + super.id;
- }
-
- @Override
- public AbstractCanvasObject makeCopy() {
- return new Node(this);
- }
-
- public String getUniqueID() {
- if(this.uniqueID == null)
- this.uniqueID = "Node "+UUID.randomUUID().toString();
- return uniqueID;
- }
- public ArrayList<String> getAllConnectedHolons(ArrayList<AbstractCanvasObject> visited) {
- ArrayList<String> conns = new ArrayList<String>();
-
- visited.add(this);
- for(Edge e : this.connections) {
- AbstractCanvasObject a = e.getA();
- AbstractCanvasObject b = e.getB();
- if(b.equals(this) && !visited.contains(a)) {
- if(a instanceof HolonObject) {
- conns.add(((HolonObject) a).holon.getUniqueID());
- } else if(a instanceof HolonSwitch) {
- conns.addAll(((HolonSwitch)a).getAllConnectedHolons(visited));
- } else if(a instanceof Node) {
- conns.addAll(((Node) a).getAllConnectedHolons(visited));
- } else if(a instanceof GroupNode) {
- conns.addAll(((GroupNode) a).getAllConnectedHolons(visited));
- }
- visited.add(a);
- } else if(a.equals(this) && !visited.contains(b)) {
- if(b instanceof HolonObject) {
- conns.add(((HolonObject) b).holon.getUniqueID());
- } else if(b instanceof HolonSwitch) {
- conns.addAll(((HolonSwitch)b).getAllConnectedHolons(visited));
- } else if(b instanceof Node) {
- conns.addAll(((Node) b).getAllConnectedHolons(visited));
- } else if(b instanceof GroupNode) {
- conns.addAll(((GroupNode) b).getAllConnectedHolons(visited));
- }
- visited.add(b);
- }
- }
-
- return conns;
- }
- }
|