Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Nov 22, 2024
1 parent 961f803 commit ce7f253
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main/java/org/htmlunit/html/DomElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@
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;
import java.util.Locale;
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;
Expand Down Expand Up @@ -598,9 +597,15 @@ public DomAttr getAttributeNodeNS(final String namespaceURI, final String localN
* @param styleMap the styles
*/
public void writeStyleToElement(final Map<String, StyleElement> styleMap) {
if (styleMap.isEmpty()) {
setAttribute("style", "");
return;
}

final StringBuilder builder = new StringBuilder();
final SortedSet<StyleElement> sortedValues = new TreeSet<>(styleMap.values());
for (final StyleElement e : sortedValues) {
final List<StyleElement> styleElements = new ArrayList<>(styleMap.values());
Collections.sort(styleElements);
for (final StyleElement e : styleElements) {
if (builder.length() != 0) {
builder.append(' ');
}
Expand All @@ -614,8 +619,7 @@ public void writeStyleToElement(final Map<String, StyleElement> styleMap) {
}
builder.append(';');
}
final String value = builder.toString();
setAttribute("style", value);
setAttribute("style", builder.toString());
}

/**
Expand Down

0 comments on commit ce7f253

Please sign in to comment.