Source:
public UnionInputGate(IndexedInputGate... inputGates) { this.inputGates = checkNotNull(inputGates); checkArgument(inputGates.length > 1, "Union input gate should union at least two input gates."); if (Arrays.stream(inputGates).map(IndexedInputGate::getGateIndex).distinct().count() != inputGates.length) { throw new IllegalArgumentException("Union of two input gates with the same gate index. Given indices: " + Arrays.stream(inputGates).map(IndexedInputGate::getGateIndex).collect(Collectors.toList())); } this.inputGatesWithRemainingData = Sets.newHashSetWithExpectedSize(inputGates.length); final int maxGateIndex = Arrays.stream(inputGates).mapToInt(IndexedInputGate::getGateIndex).max().orElse(0); inputGateChannelIndexOffsets = new int[maxGateIndex + 1]; int totalNumberOfInputChannels = 0; for (final IndexedInputGate inputGate : inputGates) { totalNumberOfInputChannels += inputGate.getNumberOfInputChannels(); } inputChannelToInputGateIndex = new int[totalNumberOfInputChannels]; int currentNumberOfInputChannels = 0; for (final IndexedInputGate inputGate : inputGates) { inputGateChannelIndexOffsets[inputGate.getGateIndex()] = currentNumberOfInputChannels; int previousNumberOfInputChannels = currentNumberOfInputChannels; currentNumberOfInputChannels += inputGate.getNumberOfInputChannels(); Arrays.fill(inputChannelToInputGateIndex, previousNumberOfInputChannels, currentNumberOfInputChannels, inputGate.getGateIndex()); } synchronized (inputGatesWithData) { for (IndexedInputGate inputGate : inputGates) { inputGatesWithRemainingData.add(inputGate); CompletableFuture<?> available = inputGate.getAvailableFuture(); if (available.isDone()) { inputGatesWithData.add(inputGate); } else { available.thenRun(() -> queueInputGate(inputGate)); } } if (!inputGatesWithData.isEmpty()) { availabilityHelper.resetAvailable(); } } }

Target:
public UnionInputGate(IndexedInputGate... inputGates) { this.inputGates = checkNotNull(inputGates); checkArgument(inputGates.length > 1, "Union input gate should union at least two input gates."); if (Arrays.stream(inputGates).map(IndexedInputGate::getGateIndex).distinct().count() != inputGates.length) { throw new IllegalArgumentException("Union of two input gates with the same gate index. Given indices: " + Arrays.stream(inputGates).map(IndexedInputGate::getGateIndex).collect(Collectors.toList())); } this.inputGatesWithRemainingData = Sets.newHashSetWithExpectedSize(inputGates.length); final int maxGateIndex = Arrays.stream(inputGates).mapToInt(IndexedInputGate::getGateIndex).max().orElse(0); inputGateChannelIndexOffsets = new int[maxGateIndex + 1]; int totalNumberOfInputChannels = Arrays.stream(inputGates).mapToInt(IndexedInputGate::getNumberOfInputChannels).sum(); inputChannelToInputGateIndex = new int[totalNumberOfInputChannels]; int currentNumberOfInputChannels = 0; for (final IndexedInputGate inputGate : inputGates) { inputGateChannelIndexOffsets[inputGate.getGateIndex()] = currentNumberOfInputChannels; int previousNumberOfInputChannels = currentNumberOfInputChannels; currentNumberOfInputChannels += inputGate.getNumberOfInputChannels(); Arrays.fill(inputChannelToInputGateIndex, previousNumberOfInputChannels, currentNumberOfInputChannels, inputGate.getGateIndex()); } synchronized (inputGatesWithData) { for (IndexedInputGate inputGate : inputGates) { inputGatesWithRemainingData.add(inputGate); CompletableFuture<?> available = inputGate.getAvailableFuture(); if (available.isDone()) { inputGatesWithData.add(inputGate); } else { available.thenRun(() -> queueInputGate(inputGate)); } } if (!inputGatesWithData.isEmpty()) { availabilityHelper.resetAvailable(); } } }