Source:
<code>private void findExcessSlots() { final Collection<ExcessResource> excessResources = new ArrayList<>(); for (ResourceProfile requirementProfile : resourceToRequirementMapping.getAllRequirementProfiles()) { int numTotalRequiredResources = resourceRequirements.getResourceCount(requirementProfile); int numTotalAcquiredResources = resourceToRequirementMapping.getNumFulfillingResources(requirementProfile); if (numTotalAcquiredResources > numTotalRequiredResources) { int numExcessResources = numTotalAcquiredResources - numTotalRequiredResources; for (Map.Entry<ResourceProfile, Integer> acquiredResource : resourceToRequirementMapping.getFulfillingResourcesFor(requirementProfile).getResourceProfilesWithCount()) { ResourceProfile acquiredResourceProfile = acquiredResource.getKey(); int numAcquiredResources = acquiredResource.getValue(); if (numAcquiredResources <= numExcessResources) { excessResources.add(new ExcessResource(requirementProfile, acquiredResourceProfile, numAcquiredResources)); numExcessResources -= numAcquiredResources; } else { excessResources.add(new ExcessResource(requirementProfile, acquiredResourceProfile, numExcessResources)); break; } } } } LOG.debug("Detected excess resources for job {}: {}", jobId, excessResources); <START> for (ExcessResource excessResource : excessResources) { <END> resourceToRequirementMapping.decrementCount(excessResource.requirementProfile, excessResource.resourceProfile, excessResource.numExcessResources); this.excessResources.incrementCount(excessResource.resourceProfile, excessResource.numExcessResources); } }</code><technical_language>Actually, this more expensive copying map twice. For map entry, write map times of entry. logs in notifyAcquiredResource misleading. job acquired some new resources calling acquired resources</technical_language>

Target:
private void findExcessSlots() { final Collection<ExcessResource> excessResources = new ArrayList<>(); for (ResourceProfile requirementProfile : resourceToRequirementMapping.getAllRequirementProfiles()) { int numTotalRequiredResources = resourceRequirements.getResourceCount(requirementProfile); int numTotalAcquiredResources = resourceToRequirementMapping.getNumFulfillingResources(requirementProfile); if (numTotalAcquiredResources > numTotalRequiredResources) { int numExcessResources = numTotalAcquiredResources - numTotalRequiredResources; for (Map.Entry<ResourceProfile, Integer> acquiredResource : resourceToRequirementMapping.getResourcesFulfilling(requirementProfile).entrySet()) { ResourceProfile acquiredResourceProfile = acquiredResource.getKey(); int numAcquiredResources = acquiredResource.getValue(); if (numAcquiredResources <= numExcessResources) { excessResources.add(new ExcessResource(requirementProfile, acquiredResourceProfile, numAcquiredResources)); numExcessResources -= numAcquiredResources; } else { excessResources.add(new ExcessResource(requirementProfile, acquiredResourceProfile, numExcessResources)); break; } } } } LOG.debug("Detected excess resources for job {}: {}", jobId, excessResources); for (ExcessResource excessResource : excessResources) { resourceToRequirementMapping.decrementCount(excessResource.requirementProfile, excessResource.resourceProfile, excessResource.numExcessResources); this.excessResources.incrementCount(excessResource.resourceProfile, excessResource.numExcessResources); } }