From 9b78b0259b4de44d5ef5ccea89aa581a123e0683 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Wed, 19 Sep 2018 13:06:28 +0300 Subject: [PATCH] [java] A sip of Java 8 --- .../openqa/selenium/logging/LogEntries.java | 25 +++++++------------ 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/java/client/src/org/openqa/selenium/logging/LogEntries.java b/java/client/src/org/openqa/selenium/logging/LogEntries.java index 1d3c3808660ca..37fb793b0b78e 100644 --- a/java/client/src/org/openqa/selenium/logging/LogEntries.java +++ b/java/client/src/org/openqa/selenium/logging/LogEntries.java @@ -17,13 +17,15 @@ package org.openqa.selenium.logging; +import static java.util.Collections.unmodifiableList; +import static java.util.stream.Collectors.toList; + import org.openqa.selenium.Beta; -import java.util.ArrayList; -import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.logging.Level; +import java.util.stream.StreamSupport; /** * Represent a pool of {@link LogEntry}. This class also provides filtering mechanisms based on @@ -35,11 +37,8 @@ public class LogEntries implements Iterable { private final List entries; public LogEntries(Iterable entries) { - List mutableEntries = new ArrayList<>(); - for (LogEntry entry : entries) { - mutableEntries.add(entry); - } - this.entries = Collections.unmodifiableList(mutableEntries); + this.entries = unmodifiableList( + StreamSupport.stream(entries.spliterator(), false).collect(toList())); } /** @@ -56,15 +55,9 @@ public List getAll() { * @return all log entries for that level and above */ public List filter(Level level) { - List toReturn = new ArrayList<>(); - - for (LogEntry entry : entries) { - if (entry.getLevel().intValue() >= level.intValue()) { - toReturn.add(entry); - } - } - - return toReturn; + return unmodifiableList(entries.stream() + .filter(entry -> entry.getLevel().intValue() >= level.intValue()) + .collect(toList())); } public Iterator iterator() {