Source:
<code>public ResponseEntity<?> commitCursors(@PathVariable("subscriptionId") final String subscriptionId, @Valid @RequestBody final ItemsWrapper<SubscriptionCursor> cursors, final Errors errors, @NotNull @RequestHeader("X-Nakadi-StreamId") final String streamId, final NativeWebRequest request, final Client client) { LOG.debug("[COMMIT_CURSORS] committing cursor(s) for subscription {}", cursors.getItems().size(), subscriptionId); if (!featureToggleService.isFeatureEnabled(HIGH_LEVEL_API)) { return new ResponseEntity<>(NOT_IMPLEMENTED); } if (errors.hasErrors()) { return Responses.create(new ValidationProblem(errors), request); } try { final List<NakadiCursor> nakadiCursors = new ArrayList<>(); for (SubscriptionCursor c : cursors.getItems()) { nakadiCursors.add(cursorConverter.convert(c)); } validateSubscriptionReadScopes(client, subscriptionId); LOG.debug("[COMMIT_CURSORS] scopes validation finished"); final List<Boolean> items = cursorsService.commitCursors(streamId, subscriptionId, nakadiCursors); LOG.debug("[COMMIT_CURSORS] commit finished"); final boolean allCommited = items.stream().allMatch(item -> item); if (allCommited) { return noContent().build(); } else { final List<CursorCommitResult> body = IntStream.range(0, cursors.getItems().size()) <START> .mapToObj( idx -> new CursorCommitResult(cursors.getItems().get(idx), items.get(idx))) <END> .collect(Collectors.toList()); return ok(new ItemsWrapper<>(body)); } } catch (final NoSuchEventTypeException | InvalidCursorException e) { return create(Problem.valueOf(UNPROCESSABLE_ENTITY, e.getMessage()), request); } catch (final NakadiException e) { return create(e.asProblem(), request); } }</code><technical_language>I do more elegant streaming list iterator of another list in stream</technical_language>

Target:
public ResponseEntity<?> commitCursors(@PathVariable("subscriptionId") final String subscriptionId, @Valid @RequestBody final ItemsWrapper<SubscriptionCursor> cursors, final Errors errors, @NotNull @RequestHeader("X-Nakadi-StreamId") final String streamId, final NativeWebRequest request, final Client client) { LOG.debug("[COMMIT_CURSORS] committing cursor(s) for subscription {}", cursors.getItems().size(), subscriptionId); if (!featureToggleService.isFeatureEnabled(HIGH_LEVEL_API)) { return new ResponseEntity<>(NOT_IMPLEMENTED); } if (errors.hasErrors()) { return Responses.create(new ValidationProblem(errors), request); } try { final List<NakadiCursor> nakadiCursors = new ArrayList<>(); for (final SubscriptionCursor cursor : cursors.getItems()) { nakadiCursors.add(cursorConverter.convert(cursor)); } validateSubscriptionReadScopes(client, subscriptionId); LOG.debug("[COMMIT_CURSORS] scopes validation finished"); final List<Boolean> items = cursorsService.commitCursors(streamId, subscriptionId, nakadiCursors); LOG.debug("[COMMIT_CURSORS] commit finished"); final boolean allCommited = items.stream().allMatch(item -> item); if (allCommited) { return noContent().build(); } else { final List<CursorCommitResult> body = IntStream.range(0, cursors.getItems().size()) .mapToObj( idx -> new CursorCommitResult(cursors.getItems().get(idx), items.get(idx))) .collect(Collectors.toList()); return ok(new ItemsWrapper<>(body)); } } catch (final NoSuchEventTypeException | InvalidCursorException e) { return create(Problem.valueOf(UNPROCESSABLE_ENTITY, e.getMessage()), request); } catch (final NakadiException e) { return create(e.asProblem(), request); } }