From ce7f2533f2375f42fec48d71792bff2079e514f9 Mon Sep 17 00:00:00 2001 From: Ronald Brill Date: Fri, 22 Nov 2024 10:05:54 +0100 Subject: [PATCH] simplify --- src/main/java/org/htmlunit/html/DomElement.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/htmlunit/html/DomElement.java b/src/main/java/org/htmlunit/html/DomElement.java index 2afea5b3a9..2729c9ef23 100644 --- a/src/main/java/org/htmlunit/html/DomElement.java +++ b/src/main/java/org/htmlunit/html/DomElement.java @@ -24,6 +24,7 @@ import java.io.StringWriter; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -31,8 +32,6 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; -import java.util.SortedSet; -import java.util.TreeSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -598,9 +597,15 @@ public DomAttr getAttributeNodeNS(final String namespaceURI, final String localN * @param styleMap the styles */ public void writeStyleToElement(final Map styleMap) { + if (styleMap.isEmpty()) { + setAttribute("style", ""); + return; + } + final StringBuilder builder = new StringBuilder(); - final SortedSet sortedValues = new TreeSet<>(styleMap.values()); - for (final StyleElement e : sortedValues) { + final List styleElements = new ArrayList<>(styleMap.values()); + Collections.sort(styleElements); + for (final StyleElement e : styleElements) { if (builder.length() != 0) { builder.append(' '); } @@ -614,8 +619,7 @@ public void writeStyleToElement(final Map styleMap) { } builder.append(';'); } - final String value = builder.toString(); - setAttribute("style", value); + setAttribute("style", builder.toString()); } /**