assert srcInput.size() == uniInput.size();
for (int i = 0, n = srcInput.size(); i < n; i++) {
FlowElementInput srcPort = srcInput.get(i);
FlowElementInput uniPort = uniInput.get(i);
for (PortConnection conn : srcPort.getConnected()) {
FlowElementOutput opposite = unifiedOutputs.get(conn.getUpstream());
assert opposite != null;
PortConnection.connect(opposite, uniPort);
}
srcPort.disconnectAll();
}
}
}
// reconnect outputs
for (FlowElement elem : elementMapping.values()) {
FlowElement unified = unifiedElements.get(elem);
assert unified != null;
if (elem != unified) {
List<FlowElementOutput> srcOutput = elem.getOutputPorts();
List<FlowElementOutput> uniOutput = unified.getOutputPorts();
assert srcOutput.size() == uniOutput.size();
for (int i = 0, n = srcOutput.size(); i < n; i++) {
FlowElementOutput srcPort = srcOutput.get(i);
FlowElementOutput uniPort = uniOutput.get(i);
for (PortConnection conn : srcPort.getConnected()) {
FlowElementInput opposite = unifiedInputs.get(conn.getDownstream());
assert opposite != null;
PortConnection.connect(uniPort, opposite);
}