sashidhar commented on a change in pull request #7764: #7316 Use Map.putIfAbsent() instead of containsKey() + put() URL: https://github.com/apache/incubator-druid/pull/7764#discussion_r287867297
########## File path: indexing-service/src/main/java/org/apache/druid/indexing/firehose/IngestSegmentFirehoseFactory.java ########## @@ -508,13 +508,14 @@ public int getNumSplits() // segments to olders. // timelineSegments are sorted in order of interval - int index = 0; + int[] index = {0}; for (TimelineObjectHolder<String, DataSegment> timelineHolder : Lists.reverse(timelineSegments)) { for (PartitionChunk<DataSegment> chunk : timelineHolder.getObject()) { for (String metric : chunk.getObject().getMetrics()) { - if (!uniqueMetrics.containsKey(metric)) { - uniqueMetrics.put(metric, index++); + uniqueMetrics.computeIfAbsent(metric, k -> { + return index[0]++; } Review comment: Using index variable as int as is, the compiler complains `"Variables used in lambda should be final or effectively final"`. The fix is to use an integer array with one element. Let me know if this is right. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org