if (foundTarget == false) {
return changed;
}
Map<FlowElementInput, FlowBlock.Input> inputs = Maps.create();
for (FlowBlock.Input input : blockInputs) {
FlowElementInput elementInput = input.getElementPort();
assert inputs.containsKey(elementInput) == false;
inputs.put(elementInput, input);
}
for (Map.Entry<FlowBlock.Input, List<FlowBlock.Output>> entry : targets.entrySet()) {
List<FlowBlock.Output> upstream = entry.getValue();
if (upstream.size() == 1) {
continue;
}
FlowElement primaryElement = upstream.get(0).getElementPort().getOwner();
assert primaryElement.getDescription().getKind() == FlowElementKind.PSEUD;
assert primaryElement.getInputPorts().size() == 1;
FlowElementInput primaryInput = primaryElement.getInputPorts().get(0);
FlowBlock.Input primarySource = inputs.get(primaryInput);
assert primarySource != null;
for (int i = 1, n = upstream.size(); i < n; i++) {
FlowBlock.Output otherTarget = upstream.get(i);
FlowElement otherElement = otherTarget.getElementPort().getOwner();
LOG.debug("Unifying pseud element: {} -> {}", otherElement, primaryElement);
assert otherElement.getDescription().getKind() == FlowElementKind.PSEUD;
assert otherElement.getInputPorts().size() == 1;
FlowElementInput otherInput = otherElement.getInputPorts().get(0);
FlowBlock.Input otherSource = inputs.get(otherInput);
assert otherSource != null;
for (FlowBlock.Connection conn : otherSource.getConnections()) {
FlowBlock.connect(conn.getUpstream(), primarySource);
}