Source:
<code>private <T extends EObject, U extends SnomedComponent> boolean updateComponents(final TransactionContext context, final Concept concept, final Iterable<T> previousComponents, final Iterable<U> currentComponents, final com.google.common.base.Function<T, String> idProvider, final Function<String, Request<TransactionContext, Void>> toDeleteRequest) { boolean changed = false; if (currentComponents == null) { return changed; } final Map<String, T> previousComponentsById = Maps.uniqueIndex(previousComponents, idProvider); final Map<String, U> currentComponentsById = Maps.uniqueIndex(currentComponents, component -> component.getId()); <START> return Sets.union(previousComponentsById.keySet(), currentComponentsById.keySet()) <END> .stream() .map(componentId -> { if (!previousComponentsById.containsKey(componentId) && currentComponentsById.containsKey(componentId)) { return currentComponentsById.get(componentId).toCreateRequest(concept.getId()); } else if (previousComponentsById.containsKey(componentId) && currentComponentsById.containsKey(componentId)) { return currentComponentsById.get(componentId).toUpdateRequest(); } else if (previousComponentsById.containsKey(componentId) && !currentComponentsById.containsKey(componentId)) { return toDeleteRequest.apply(componentId); } else { throw new IllegalStateException("Invalid case, should not happen"); } }) .map(req -> req.execute(context)) .filter(Boolean.class::isInstance) .map(Boolean.class::cast) .reduce(Boolean.FALSE, (r1, r2) -> r1 || r2); }</code><technical_language>thought, splitting call Set operations middle mapping function easier: * Sets.difference(previous, current) for deletions * Sets.difference(current, previous) for creations * Sets.intersection(previous, current) for changes</technical_language>

Target:
private <T extends EObject, U extends SnomedComponent> boolean updateComponents(final TransactionContext context, final Concept concept, final Iterable<T> previousComponents, final Iterable<U> currentComponents, final com.google.common.base.Function<T, String> idProvider, final Function<String, Request<TransactionContext, Void>> toDeleteRequest) { boolean changed = false; if (currentComponents == null) { return changed; } currentComponents.forEach(component -> { if (Strings.isNullOrEmpty(component.getId())) { throw new BadRequestException("New components require their id to be set."); } if (Strings.isNullOrEmpty(component.getModuleId())) { throw new BadRequestException("It is required to specify the moduleId for the components."); } }); final Map<String, T> previousComponentsById = Maps.uniqueIndex(previousComponents, idProvider); final Map<String, U> currentComponentsById = Maps.uniqueIndex(currentComponents, component -> component.getId()); return Sets.union(previousComponentsById.keySet(), currentComponentsById.keySet()) .stream() .map(componentId -> { if (!previousComponentsById.containsKey(componentId) && currentComponentsById.containsKey(componentId)) { return currentComponentsById.get(componentId).toCreateRequest(concept.getId()); } else if (previousComponentsById.containsKey(componentId) && currentComponentsById.containsKey(componentId)) { return currentComponentsById.get(componentId).toUpdateRequest(); } else if (previousComponentsById.containsKey(componentId) && !currentComponentsById.containsKey(componentId)) { return toDeleteRequest.apply(componentId); } else { throw new IllegalStateException("Invalid case, should not happen"); } }) .map(req -> req.execute(context)) .filter(Boolean.class::isInstance) .map(Boolean.class::cast) .reduce(Boolean.FALSE, (r1, r2) -> r1 || r2); }