Source:
<code>private List<ResourceEntry> removeAndGet(ScalarResourceEntry scalarResourceEntry, Collection<ReservationType> reservationTypesListByPriority) throws ResourceNotAvailabeException { Double requiredValue = scalarResourceEntry.getValue(); List<ResourceEntry> reservedResources = new ArrayList<>(); if (requiredValue > totalAvailableResource) { String message = String.format("ResourceType '%s' is not available. Requested value: %s Available: %s", resourceType, requiredValue, totalAvailableResource); throw new ResourceNotAvailabeException(message); } for (ReservationType reservationType : reservationTypesListByPriority) { ScalarResourceEntry availableResource = availableResourcesByReservationType.get(reservationType); Double availableResourceValue = availableResource.getValue(); if (availableResourceValue >= requiredValue) { availableResource.remove(new ScalarResourceEntry(requiredValue)); totalAvailableResource -= requiredValue; reservedResources.add(new ScalarResourceEntry(reservationType, requiredValue)); return reservedResources; } else if (availableResourceValue > 0) { <START> availableResourcesByReservationType.put(reservationType, new ScalarResourceEntry(reservationType, 0.0)); <END> requiredValue -= availableResourceValue; totalAvailableResource -= availableResourceValue; reservedResources.add(new ScalarResourceEntry(reservationType, availableResourceValue)); } } return reservedResources; }</code><technical_language>reading is logic flows if (requested resources fit resources) remove requested resources form resources reduce total resources requested resources reserve requested resources return reserved resources else if (there resources, requested resources available) add "empty" resource list of resources for this reservation type reduce total resources amount of resources reserve resource positive I understand remove entire resource calling availableResource.remove(new ScalarResourceEntry(availableResourceValue)) (as is similar is done in if) else if requires pay special attention reservationType (where if ignore reservationType reserve resources)</technical_language>

Target:
private List<ResourceEntry> removeAndGet(ScalarResourceEntry scalarResourceEntry, Collection<ReservationType> reservationTypesListByPriority) throws ResourceNotAvailableException { Double requiredValue = scalarResourceEntry.getValue(); List<ResourceEntry> reservedResources = new ArrayList<>(); if (requiredValue > totalAvailableResource) { String message = String.format("ResourceType '%s' is not available. Requested value: %s Available: %s", resourceType, requiredValue, totalAvailableResource); throw new ResourceNotAvailableException(message); } for (ReservationType reservationType : reservationTypesListByPriority) { ScalarResourceEntry availableResource = availableResourcesByReservationType.get(reservationType); Double availableResourceValue = availableResource.getValue(); if (availableResourceValue >= requiredValue) { availableResource.remove(new ScalarResourceEntry(requiredValue)); totalAvailableResource -= requiredValue; reservedResources.add(new ScalarResourceEntry(reservationType, requiredValue)); return reservedResources; } else if (availableResourceValue > 0) { availableResourcesByReservationType.put(reservationType, new ScalarResourceEntry(reservationType, 0.0)); requiredValue -= availableResourceValue; totalAvailableResource -= availableResourceValue; reservedResources.add(new ScalarResourceEntry(reservationType, availableResourceValue)); } } return reservedResources; }