diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-01-03 14:42:50 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-01-03 14:42:50 +0000 |
| commit | 4f8c4b581f16551a364e203fd8142f7717101a2f (patch) | |
| tree | 077bb2fd98d675a039478980b90ffe77616de42f /src/main/java | |
| parent | 6e97bf5bb28ad5a63f396873399a457be6fe779d (diff) | |
Add list as shorter alias of ImmutableList.of
Diffstat (limited to 'src/main/java')
4 files changed, 32 insertions, 15 deletions
diff --git a/src/main/java/org/zwobble/mammoth/docx/BodyXmlReader.java b/src/main/java/org/zwobble/mammoth/docx/BodyXmlReader.java index a61e4dd..33fc5b0 100644 --- a/src/main/java/org/zwobble/mammoth/docx/BodyXmlReader.java +++ b/src/main/java/org/zwobble/mammoth/docx/BodyXmlReader.java @@ -9,9 +9,8 @@ import org.zwobble.mammoth.xml.XmlNode; import java.util.List; import java.util.Optional; -import static com.google.common.collect.Iterables.concat; -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.transform; +import static com.google.common.collect.Iterables.*; +import static org.zwobble.mammoth.util.MammothLists.list; public class BodyXmlReader { private final Styles styles; @@ -23,18 +22,18 @@ public class BodyXmlReader { public List<DocumentElement> readElement(XmlElement element) { switch (element.getName()) { case "w:t": - return ImmutableList.of(new Text(element.innerText())); + return list(new Text(element.innerText())); case "w:r": - return ImmutableList.of(new Run(readElements(element.children()))); + return list(new Run(readElements(element.children()))); case "w:p": - return ImmutableList.of(readParagraph(element)); + return list(readParagraph(element)); case "w:pPr": - return ImmutableList.of(); + return list(); default: // TODO: emit warning - return ImmutableList.of(); + return list(); } } diff --git a/src/main/java/org/zwobble/mammoth/docx/OfficeXml.java b/src/main/java/org/zwobble/mammoth/docx/OfficeXml.java index a1d156f..43d86ad 100644 --- a/src/main/java/org/zwobble/mammoth/docx/OfficeXml.java +++ b/src/main/java/org/zwobble/mammoth/docx/OfficeXml.java @@ -13,6 +13,7 @@ import java.util.List; import static com.google.common.collect.Iterables.concat; import static com.google.common.collect.Iterables.transform; +import static org.zwobble.mammoth.util.MammothLists.list; public class OfficeXml { private static ImmutableBiMap<String, String> XML_NAMESPACES = ImmutableBiMap.<String, String>builder() @@ -44,13 +45,13 @@ public class OfficeXml { element.getName(), element.getAttributes(), ImmutableList.copyOf(concat(transform(element.children(), OfficeXml::collapseAlternateContent)))); - return ImmutableList.of(collapsedElement); + return list(collapsedElement); } } @Override public List<XmlNode> visit(XmlTextNode textNode) { - return ImmutableList.of(textNode); + return list(textNode); } }); } diff --git a/src/main/java/org/zwobble/mammoth/util/MammothLists.java b/src/main/java/org/zwobble/mammoth/util/MammothLists.java new file mode 100644 index 0000000..e038ec7 --- /dev/null +++ b/src/main/java/org/zwobble/mammoth/util/MammothLists.java @@ -0,0 +1,19 @@ +package org.zwobble.mammoth.util; + +import com.google.common.collect.ImmutableList; + +import java.util.List; + +public class MammothLists { + public static <T> List<T> list() { + return ImmutableList.of(); + } + + public static <T> List<T> list(T value1) { + return ImmutableList.of(value1); + } + + public static <T> List<T> list(T value1, T value2) { + return ImmutableList.of(value1, value2); + } +} diff --git a/src/main/java/org/zwobble/mammoth/xml/XmlNodes.java b/src/main/java/org/zwobble/mammoth/xml/XmlNodes.java index 9531f17..cf548ab 100644 --- a/src/main/java/org/zwobble/mammoth/xml/XmlNodes.java +++ b/src/main/java/org/zwobble/mammoth/xml/XmlNodes.java @@ -1,20 +1,18 @@ package org.zwobble.mammoth.xml; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; - import java.util.List; import java.util.Map; +import static org.zwobble.mammoth.util.MammothLists.list; import static org.zwobble.mammoth.util.MammothMaps.map; public class XmlNodes { public static XmlElement element(String name) { - return element(name, ImmutableList.of()); + return element(name, list()); } public static XmlElement element(String name, Map<String, String> attributes) { - return element(name, attributes, ImmutableList.of()); + return element(name, attributes, list()); } public static XmlElement element(String name, List<XmlNode> children) { |
