divijvaidya commented on code in PR #12045: URL: https://github.com/apache/kafka/pull/12045#discussion_r897724648
########## clients/src/main/java/org/apache/kafka/common/metrics/stats/SampledStat.java: ########## @@ -84,13 +106,7 @@ public Sample current(long timeMs) { public Sample oldest(long now) { if (samples.size() == 0) this.samples.add(newSample(now)); - Sample oldest = this.samples.get(0); - for (int i = 1; i < this.samples.size(); i++) { - Sample curr = this.samples.get(i); - if (curr.lastWindowMs < oldest.lastWindowMs) - oldest = curr; - } - return oldest; + return samples.stream().min(Comparator.comparingLong(s -> s.lastWindowMs)).orElse(samples.get(0)); Review Comment: I find the new code more readable since we can immediately eye ball that a min is being calculated vs. in the previous version where we have to understand the assignments and logic in for loop to determine what is going on. Nevertheless, I don't have strong opinion on this one. If you still think we need to revert it back, I will do it. Let me know. -- 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. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org