From 84787e2d7f003022fbad66611b8917f75bacf1db Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Sat, 29 Jul 2023 08:00:39 +0530 Subject: [PATCH] Uncomment stream block in Element --- pom.xml | 5 +++++ src/main/java/org/jsoup/nodes/Element.java | 11 +++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 48ec01bbf3..9aa7ad9b73 100644 --- a/pom.xml +++ b/pom.xml @@ -78,9 +78,14 @@ 2.3.3_r2 + java.util.Set java.util.function.Consumer + java.util.function.Function java.util.function.Supplier java.lang.ThreadLocal + java.util.stream.Collector + java.util.stream.Collectors + java.util.stream.Stream diff --git a/src/main/java/org/jsoup/nodes/Element.java b/src/main/java/org/jsoup/nodes/Element.java index 3d5f8c15fa..c76347852a 100644 --- a/src/main/java/org/jsoup/nodes/Element.java +++ b/src/main/java/org/jsoup/nodes/Element.java @@ -6,6 +6,7 @@ import org.jsoup.internal.StringUtil; import org.jsoup.parser.ParseSettings; import org.jsoup.parser.Tag; +import org.jsoup.parser.TokenQueue; import org.jsoup.select.Collector; import org.jsoup.select.Elements; import org.jsoup.select.Evaluator; @@ -30,6 +31,7 @@ import java.util.function.Consumer; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import java.util.stream.Collectors; import static org.jsoup.internal.Normalizer.normalize; import static org.jsoup.nodes.TextNode.lastCharIsWhitespace; @@ -843,12 +845,9 @@ public String cssSelector() { // Escape tagname, and translate HTML namespace ns:tag to CSS namespace syntax ns|tag String tagName = escapeCssIdentifier(tagName()).replace("\\:", "|"); StringBuilder selector = StringUtil.borrowBuilder().append(tagName); - // String classes = StringUtil.join(classNames().stream().map(TokenQueue::escapeCssIdentifier).iterator(), "."); - // todo - replace with ^^ in 1.16.1 when we enable Android support for stream etc - StringUtil.StringJoiner escapedClasses = new StringUtil.StringJoiner("."); - for (String name : classNames()) escapedClasses.add(escapeCssIdentifier(name)); - String classes = escapedClasses.complete(); - if (classes.length() > 0) + String classes = classNames().stream().map(TokenQueue::escapeCssIdentifier) + .collect(Collectors.joining(".")); + if (!classes.isEmpty()) selector.append('.').append(classes); if (parent() == null || parent() instanceof Document) // don't add Document to selector, as will always have a html node