Source:
<code>private Observable<IndexOperationMessage> processBatch( final IndexOperationMessage batch ) { final Set<IndexOperation> indexOperationSet = batch.getIndexRequests(); final Set<DeIndexOperation> deIndexOperationSet = batch.getDeIndexRequests(); final int indexOperationSetSize = indexOperationSet.size(); final int deIndexOperationSetSize = deIndexOperationSet.size(); log.debug("Emitting add and remove operations", indexOperationSetSize, deIndexOperationSetSize); indexSizeCounter.dec(indexOperationSetSize); indexSizeCounter.dec(deIndexOperationSetSize); final Observable<IndexOperation> index = Observable.from(batch.getIndexRequests()); final Observable<DeIndexOperation> deIndex = Observable.from(batch.getDeIndexRequests()); final Observable<BatchOperation> batchOps = Observable.merge(index, deIndex); final Observable<BulkRequestBuilder> requests = batchOps.buffer(indexFig.getIndexBatchSize()) .flatMap(individualOps -> Observable.from(individualOps) .collect(() -> initRequest(), (bulkRequestBuilder, batchOperation) -> { log.debug("adding operation to bulkRequestBuilder {}", batchOperation, bulkRequestBuilder); batchOperation.doOperation(client, bulkRequestBuilder); })) .doOnNext(bulkRequestBuilder -> sendRequest(bulkRequestBuilder)); final Observable<IndexOperationMessage> processedIndexOperations = <START> requests.lastOrDefault(null).flatMap(lastRequest -> { <END> if (lastRequest != null) { return Observable.just(batch); } else { return Observable.empty(); } }); return processedIndexOperations.doOnNext(processedIndexOp -> { roundtripTimer.update(System.currentTimeMillis() - processedIndexOp.getCreationTime()); }); }</code><technical_language>I get rid of this lastOrDefaultRight? batch</technical_language>

Target:
private Observable<IndexOperationMessage> processBatch( final IndexOperationMessage batch ) { final Set<IndexOperation> indexOperationSet = batch.getIndexRequests(); final Set<DeIndexOperation> deIndexOperationSet = batch.getDeIndexRequests(); final int indexOperationSetSize = indexOperationSet.size(); final int deIndexOperationSetSize = deIndexOperationSet.size(); log.debug("Emitting add and remove operations", indexOperationSetSize, deIndexOperationSetSize); indexSizeCounter.dec(indexOperationSetSize); indexSizeCounter.dec(deIndexOperationSetSize); final Observable<IndexOperation> index = Observable.from(batch.getIndexRequests()); final Observable<DeIndexOperation> deIndex = Observable.from(batch.getDeIndexRequests()); final Observable<BatchOperation> batchOps = Observable.merge(index, deIndex); final Observable<BulkRequestBuilder> requests = batchOps.buffer(indexFig.getIndexBatchSize()) .flatMap(individualOps -> Observable.from(individualOps) .collect(() -> initRequest(), (bulkRequestBuilder, batchOperation) -> { log.debug("adding operation to bulkRequestBuilder {}", batchOperation, bulkRequestBuilder); batchOperation.doOperation(client, bulkRequestBuilder); })) .doOnNext(bulkRequestBuilder -> sendRequest(bulkRequestBuilder)); final Observable<IndexOperationMessage> processedIndexOperations = requests.flatMap(lastRequest -> { if (lastRequest != null) { return Observable.just(batch); } else { return Observable.empty(); } }); return processedIndexOperations.doOnNext(processedIndexOp -> { roundtripTimer.update(System.currentTimeMillis() - processedIndexOp.getCreationTime()); }); }