Source:
<code>public Map<Partition.PartitionKey, NakadiCursor> getSubscriptionOffsets() { try { final List<NakadiCursor> existingPositions = new ArrayList<>(); switch (subscription.getReadFrom()) { case BEGIN: for (String eventType : subscription.getEventTypes()) { final Timeline timeline = timelineService.getActiveTimelinesOrdered(eventType).get(0); timelineService.getTopicRepository(timeline) .loadTopicStatistics(Collections.singletonList(timeline)) .forEach(stat -> existingPositions.add(stat.getBeforeFirst())); } break; case END: for (String eventType : subscription.getEventTypes()) { final Timeline timeline = timelineService.getActiveTimelinesOrdered(eventType).get(0); timelineService.getTopicRepository(timeline) .loadTopicStatistics(Collections.singletonList(timeline)) .forEach(stat -> existingPositions.add(stat.getLast())); } <START> break; <END> case CURSORS: subscription.getInitialCursors().forEach(cursor -> { try { existingPositions.add(cursorConverter.convert(cursor.getEventType(), cursor)); } catch (final Exception e) { throw new NakadiRuntimeException(e); } }); break; default: throw new IllegalStateException("unsupported start position " + subscription.getReadFrom() + " for subscription " + subscription.getId()); } return existingPositions.stream().collect( Collectors.toMap( cursor -> new Partition.PartitionKey(cursor.getTopic(), cursor.getPartition()), cursor -> cursor )); } catch (final NakadiException e) { throw new NakadiRuntimeException(e); } }</code><technical_language>branches for END identical. I code improved avoid duplication. For example, check if END do stat.getBeforeFirst() stat.getLast()</technical_language>

Target:
public Map<Partition.PartitionKey, NakadiCursor> getSubscriptionOffsets() { try { final List<NakadiCursor> existingPositions = new ArrayList<>(); switch (subscription.getReadFrom()) { case BEGIN: for (final String eventType : subscription.getEventTypes()) { final List<Timeline> activeTimelines = timelineService.getActiveTimelinesOrdered(eventType); final Timeline timeline = activeTimelines.get(0); timelineService.getTopicRepository(timeline) .loadTopicStatistics(Collections.singletonList(timeline)) .forEach(stat -> existingPositions.add(stat.getBeforeFirst())); } break; case END: for (final String eventType : subscription.getEventTypes()) { final List<Timeline> activeTimelines = timelineService.getActiveTimelinesOrdered(eventType); final Timeline timeline = activeTimelines.get(activeTimelines.size() - 1); timelineService.getTopicRepository(timeline) .loadTopicStatistics(Collections.singletonList(timeline)) .forEach(stat -> existingPositions.add(stat.getLast())); } break; case CURSORS: subscription.getInitialCursors().forEach(cursor -> { try { existingPositions.add(cursorConverter.convert(cursor)); } catch (final Exception e) { throw new NakadiRuntimeException(e); } }); break; default: throw new IllegalStateException("unsupported start position " + subscription.getReadFrom() + " for subscription " + subscription.getId()); } return existingPositions.stream().collect( Collectors.toMap( cursor -> new Partition.PartitionKey(cursor.getTopic(), cursor.getPartition()), cursor -> cursor )); } catch (final NakadiException e) { throw new NakadiRuntimeException(e); } }