final Set<ValueRequirement> specificRequirements = calcConfig.getSpecificRequirements();
final Pair<DependencyGraph, Set<ValueRequirement>> previousGraphEntry = previousGraphs.get(calcConfig.getName());
if (previousGraphEntry == null) {
continue;
}
final DependencyGraph previousGraph = previousGraphEntry.getFirst();
final Map<ValueSpecification, Set<ValueRequirement>> terminalOutputs = previousGraph.getTerminalOutputs();
final ValueSpecification[] removeSpecifications = new ValueSpecification[terminalOutputs.size()];
@SuppressWarnings("unchecked")
final List<ValueRequirement>[] removeRequirements = new List[terminalOutputs.size()];
int remove = 0;
for (final Map.Entry<ValueSpecification, Set<ValueRequirement>> entry : terminalOutputs.entrySet()) {
if (unmapped.contains(entry.getKey().getTargetSpecification().getUniqueId())) {
List<ValueRequirement> removal = null;
for (final ValueRequirement requirement : entry.getValue()) {
if (!specificRequirements.contains(requirement)) {
if (removal == null) {
removal = new ArrayList<>(entry.getValue().size());
}
removal.add(requirement);
}
// Anything that was in the specific requirements will be captured by the standard invalid identifier tests
}
if (removal != null) {
removeSpecifications[remove] = entry.getKey();
removeRequirements[remove++] = removal;
}
}
}
for (int i = 0; i < remove; i++) {
previousGraph.removeTerminalOutputs(removeRequirements[i], removeSpecifications[i]);
}
if (!mapped.isEmpty()) {
final ComputationTargetIdentifierRemapVisitor remapper = new ComputationTargetIdentifierRemapVisitor(mapped);
final Collection<Object> replacements = new ArrayList<>(mapped.size() * 2);
for (DependencyNode node : previousGraph.getDependencyNodes()) {
final ComputationTargetSpecification newTarget = remapper.remap(node.getComputationTarget());
if (newTarget != null) {
replacements.add(node);
replacements.add(newTarget);
}
}
Iterator<Object> itrReplacements = replacements.iterator();
while (itrReplacements.hasNext()) {
final DependencyNode node = (DependencyNode) itrReplacements.next();
final ComputationTargetSpecification newTarget = (ComputationTargetSpecification) itrReplacements.next();
s_logger.debug("Rewriting {} to {}", node, newTarget);
previousGraph.replaceNode(node, newTarget);
}
// Rewrite the original value requirements that might have referenced the original nodes
for (Map.Entry<ValueSpecification, Set<ValueRequirement>> terminalOutput : previousGraph.getTerminalOutputs().entrySet()) {
final Set<ValueRequirement> oldReqs = terminalOutput.getValue();
replacements.clear();
for (ValueRequirement req : oldReqs) {
final ComputationTargetReference newTarget = req.getTargetReference().accept(remapper);
if (newTarget != null) {