Source:
<code>public Collection<WindowPane<K, Object>> handleMessage( M message, MessageCollector collector, TaskCoordinator coordinator) { LOG.trace("Processing message envelope: {}", message); List<WindowPane<K, Object>> results = new ArrayList<>(); WindowKey<K> windowKey = getWindowKey(message); long timestamp = Long.parseLong(windowKey.getPaneId()); K key = windowKey.getKey(); if (window.getFoldLeftFunction() == null) { timeSeriesDb.put(key, message, timestamp); } else { <START> List<Object> existingState = getValues(windowKey); <END> Preconditions.checkState(existingState.size() == 1, "Store with FoldLeftFunction should not contain more than one entry per window"); Object aggregatedValue = applyFoldFunction(existingState.get(0), message); timeSeriesDb.put(key, aggregatedValue, timestamp); } if (window.getEarlyTrigger() != null) { TriggerKey<K> triggerKey = new TriggerKey<>(FiringType.EARLY, windowKey); TriggerImplHandler triggerImplHandler = getOrCreateTriggerImplHandler(triggerKey, window.getEarlyTrigger()); Optional<WindowPane<K, Object>> maybeTriggeredPane = triggerImplHandler.onMessage(triggerKey, message, collector, coordinator); maybeTriggeredPane.ifPresent(results::add); } if (window.getDefaultTrigger() != null) { TriggerKey<K> triggerKey = new TriggerKey<>(FiringType.DEFAULT, windowKey); TriggerImplHandler triggerImplHandler = getOrCreateTriggerImplHandler(triggerKey, window.getDefaultTrigger()); Optional<WindowPane<K, Object>> maybeTriggeredPane = triggerImplHandler.onMessage(triggerKey, message, collector, coordinator); maybeTriggeredPane.ifPresent(results::add); } return results; }</code><technical_language>new convenience getN API here</technical_language>

Target:
public Collection<WindowPane<K, Object>> handleMessage( M message, MessageCollector collector, TaskCoordinator coordinator) { LOG.trace("Processing message envelope: {}", message); List<WindowPane<K, Object>> results = new ArrayList<>(); K key = (keyFn != null) ? keyFn.apply(message) : null; long timestamp = getWindowTimestamp(message); if (foldLeftFn == null) { timeSeriesStore.put(key, message, timestamp); } else { List<Object> existingState = getValues(key, timestamp); Preconditions.checkState(existingState.size() == 1, "WindowState for aggregating windows " + "must not contain more than one entry per window"); Object oldVal = existingState.get(0); if (oldVal == null) { LOG.trace("No existing state found for key. Invoking initializer."); oldVal = initializer.get(); } Object aggregatedValue = foldLeftFn.apply(message, oldVal); timeSeriesStore.put(key, aggregatedValue, timestamp); } if (window.getEarlyTrigger() != null) { TriggerKey<K> triggerKey = new TriggerKey<>(FiringType.EARLY, key, timestamp); TriggerImplHandler triggerImplHandler = getOrCreateTriggerImplHandler(triggerKey, window.getEarlyTrigger()); Optional<WindowPane<K, Object>> maybeTriggeredPane = triggerImplHandler.onMessage(triggerKey, message, collector, coordinator); maybeTriggeredPane.ifPresent(results::add); } if (window.getDefaultTrigger() != null) { TriggerKey<K> triggerKey = new TriggerKey<>(FiringType.DEFAULT, key, timestamp); TriggerImplHandler triggerImplHandler = getOrCreateTriggerImplHandler(triggerKey, window.getDefaultTrigger()); Optional<WindowPane<K, Object>> maybeTriggeredPane = triggerImplHandler.onMessage(triggerKey, message, collector, coordinator); maybeTriggeredPane.ifPresent(results::add); } return results; }