// The extended for loop cannot be used to remove the elements.
// Remove edges connected to input ports.
for (Iterator<DataPort> portItr = nodeImpl.getInputPorts().iterator(); portItr
.hasNext();) {
DataPort port = portItr.next();
for (Iterator<DataEdge> edgeItr = port.getEdges().iterator(); edgeItr
.hasNext();) {
DataEdge edge = edgeItr.next();
// Remove the edge from from-port.
DataPort fromPort = edge.getFromPort();
fromPort.removeEdge(edge);
// remove the edge from this port. This is necessary so that
// type update works properly.
edgeItr.remove();
// Remove the edge from the graph.
this.edges.remove(edge);
fromPort.getNode().edgeWasRemoved(edge);
}
// Remove the port from the node.
portItr.remove();
// Remove the port from the graph.
this.ports.remove(port);
}
// Remove edges connected to output ports.
for (Iterator<DataPort> portItr = nodeImpl.getOutputPorts().iterator(); portItr
.hasNext();) {
DataPort port = portItr.next();
for (Iterator<DataEdge> edgeItr = port.getEdges().iterator(); edgeItr
.hasNext();) {
DataEdge edge = edgeItr.next();
DataPort toPort = edge.getToPort();
toPort.removeEdge(edge);
edgeItr.remove();
this.edges.remove(edge);
toPort.getNode().edgeWasRemoved(edge);
}
portItr.remove();
this.ports.remove(port);
}
for (Iterator<ControlPort> portItr = nodeImpl.getControlOutPorts()
.iterator(); portItr.hasNext();) {
PortImpl port = portItr.next();
for (Iterator<? extends EdgeImpl> edgeItr = port.getEdges()
.iterator(); edgeItr.hasNext();) {
EdgeImpl edge = edgeItr.next();
PortImpl toPort = edge.getToPort();
toPort.removeEdge(edge);
edgeItr.remove();
this.edges.remove(edge);
toPort.getNode().edgeWasRemoved(edge);
}
portItr.remove();
this.ports.remove(port);
}
PortImpl controlInPort = nodeImpl.getControlInPort();
if (controlInPort != null) {
for (Iterator<? extends EdgeImpl> edgeItr = controlInPort
.getEdges().iterator(); edgeItr.hasNext();) {
EdgeImpl edge = edgeItr.next();
PortImpl fromPort = edge.getFromPort();
fromPort.removeEdge(edge);
edgeItr.remove();
this.edges.remove(edge);
fromPort.getNode().edgeWasRemoved(edge);
}
this.ports.remove(controlInPort);
}
PortImpl eprPort = nodeImpl.getEPRPort();
if (eprPort != null) {
for (Iterator<? extends EdgeImpl> edgeItr = eprPort.getEdges()
.iterator(); edgeItr.hasNext();) {
EdgeImpl edge = edgeItr.next();
PortImpl toPort = edge.getToPort();
toPort.removeEdge(edge);
edgeItr.remove();
this.edges.remove(edge);
toPort.getNode().edgeWasRemoved(edge);
}
this.ports.remove(eprPort);
}
this.nodes.remove(node);