From 622c04d788615dc79665203ea9a61e57e1935c49 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 14 Feb 2016 11:42:44 +0000 Subject: Rename HtmlElementNode to HtmlElement --- src/main/java/org/zwobble/mammoth/html/Html.java | 2 +- .../java/org/zwobble/mammoth/html/HtmlElement.java | 49 ++++++++++++++++++++++ .../org/zwobble/mammoth/html/HtmlElementNode.java | 49 ---------------------- 3 files changed, 50 insertions(+), 50 deletions(-) create mode 100644 src/main/java/org/zwobble/mammoth/html/HtmlElement.java delete mode 100644 src/main/java/org/zwobble/mammoth/html/HtmlElementNode.java (limited to 'src/main/java/org') diff --git a/src/main/java/org/zwobble/mammoth/html/Html.java b/src/main/java/org/zwobble/mammoth/html/Html.java index c89a41b..ef6bcf9 100644 --- a/src/main/java/org/zwobble/mammoth/html/Html.java +++ b/src/main/java/org/zwobble/mammoth/html/Html.java @@ -26,7 +26,7 @@ public class Html { } public static HtmlNode element(String tagName, Map attributes, List children) { - return new HtmlElementNode(tagName, attributes, children); + return new HtmlElement(tagName, attributes, children); } public static HtmlNode selfClosingElement(String tagName) { diff --git a/src/main/java/org/zwobble/mammoth/html/HtmlElement.java b/src/main/java/org/zwobble/mammoth/html/HtmlElement.java new file mode 100644 index 0000000..312cebe --- /dev/null +++ b/src/main/java/org/zwobble/mammoth/html/HtmlElement.java @@ -0,0 +1,49 @@ +package org.zwobble.mammoth.html; + +import com.google.common.base.Function; +import com.google.common.collect.Ordering; + +import java.util.List; +import java.util.Map; + +public class HtmlElement implements HtmlNode { + private final String tagName; + private final Map attributes; + private final List children; + + public HtmlElement(String tagName, Map attributes, List children) { + this.tagName = tagName; + this.attributes = attributes; + this.children = children; + } + + @Override + public void write(StringBuilder builder) { + builder.append("<").append(tagName); + + List> sortedAttributes = orderBy(Map.Entry::getKey) + .sortedCopy(attributes.entrySet()); + + for (Map.Entry attribute : sortedAttributes) { + builder + .append(" ") + .append(attribute.getKey()) + .append("=\"") + .append(attribute.getValue()) + .append("\""); + } + + builder.append(">"); + + children.forEach(node -> node.write(builder)); + + builder + .append(""); + } + + private static > Ordering orderBy(Function getKey) { + return Ordering.from((first, second) -> getKey.apply(first).compareTo(getKey.apply(second))); + } +} diff --git a/src/main/java/org/zwobble/mammoth/html/HtmlElementNode.java b/src/main/java/org/zwobble/mammoth/html/HtmlElementNode.java deleted file mode 100644 index d237f6b..0000000 --- a/src/main/java/org/zwobble/mammoth/html/HtmlElementNode.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.zwobble.mammoth.html; - -import com.google.common.base.Function; -import com.google.common.collect.Ordering; - -import java.util.List; -import java.util.Map; - -public class HtmlElementNode implements HtmlNode { - private final String tagName; - private final Map attributes; - private final List children; - - public HtmlElementNode(String tagName, Map attributes, List children) { - this.tagName = tagName; - this.attributes = attributes; - this.children = children; - } - - @Override - public void write(StringBuilder builder) { - builder.append("<").append(tagName); - - List> sortedAttributes = orderBy(Map.Entry::getKey) - .sortedCopy(attributes.entrySet()); - - for (Map.Entry attribute : sortedAttributes) { - builder - .append(" ") - .append(attribute.getKey()) - .append("=\"") - .append(attribute.getValue()) - .append("\""); - } - - builder.append(">"); - - children.forEach(node -> node.write(builder)); - - builder - .append(""); - } - - private static > Ordering orderBy(Function getKey) { - return Ordering.from((first, second) -> getKey.apply(first).compareTo(getKey.apply(second))); - } -} -- cgit v1.2.3