for (final CompositionNode.Emitter emitter : subtreeNodeInfo.getEmitters()) {
if (emitter.getCollectorNode() == collector) {
nEmitterArgs = emitter.getNArguments();
for (int i = 0; i < nEmitterArgs; i++) {
CompositionArgument emitterArgument = emitter.getNodeArgument(i);
if (emitterArgument.getConnectedNode() == null && !emitterArgument.isBurnt()) {
collectorEmitterArgumentToIndexMap.put(emitterArgument, Integer.valueOf(i));
}
}
}
}
// Another check for nothing to do..
if (nEmitterArgs < 0 || collectorEmitterArgumentToIndexMap.isEmpty()) {
continue;
}
// Calculate the reflected inputs for the collector.
// These are the target arguments which are also descendant free unburnt args, but which are not recursive emitter args.
List<CompositionArgument> descendantFreeUnburntArguments = subtreeNodeInfo.getFreeUnburntArguments();
Set<CompositionArgument> reflectedArguments = new LinkedHashSet<CompositionArgument>(collector.getTargetArguments());
reflectedArguments.retainAll(descendantFreeUnburntArguments);
reflectedArguments.removeAll(collectorEmitterArgumentToIndexMap.keySet());
if (nEmitterArgs != reflectedArguments.size()) {
throw new IllegalStateException("The number of reflected arguments must be equal to the number of emitter args. "
+ nEmitterArgs + " != " + reflectedArguments.size());
}
// Map from emitter arg index to the argument reflected at that index.
Map<Integer, CompositionArgument> indexToReflectedArgumentMap = new HashMap<Integer, CompositionArgument>();
int index = 0;
for (final CompositionArgument arg : reflectedArguments) {
indexToReflectedArgumentMap.put(Integer.valueOf(index), arg);
index++;
}
// Now add all recursive args to the recursiveEmitterArgumentToReflectedInputMap.
for (final Map.Entry<CompositionArgument, Integer> entry : collectorEmitterArgumentToIndexMap.entrySet()) {
final CompositionArgument collectorEmitterArgument = entry.getKey();
Integer argIndex = entry.getValue();
recursiveEmitterArgumentToReflectedInputMap.put(collectorEmitterArgument, indexToReflectedArgumentMap.get(argIndex));
}
}