aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-01-03 14:36:59 +0000
committerMichael Williamson <mike@zwobble.org>2016-01-03 14:36:59 +0000
commit4f8ad8f0588564679cb8ccb9ae4592738810d800 (patch)
treefa8d0d1c2115079e362e0218b5d530f1502138c4 /src/main
parent07685b4a361f8827728513f9d7360bd91dc1a246 (diff)
Add map as shorter alias for ImmutableMap.of
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/zwobble/mammoth/Mammoth.java6
-rw-r--r--src/main/java/org/zwobble/mammoth/docx/Styles.java5
-rw-r--r--src/main/java/org/zwobble/mammoth/util/MammothMaps.java16
-rw-r--r--src/main/java/org/zwobble/mammoth/xml/XmlElement.java4
-rw-r--r--src/main/java/org/zwobble/mammoth/xml/XmlNodes.java4
5 files changed, 25 insertions, 10 deletions
diff --git a/src/main/java/org/zwobble/mammoth/Mammoth.java b/src/main/java/org/zwobble/mammoth/Mammoth.java
index e2408e9..e834b3b 100644
--- a/src/main/java/org/zwobble/mammoth/Mammoth.java
+++ b/src/main/java/org/zwobble/mammoth/Mammoth.java
@@ -1,19 +1,15 @@
package org.zwobble.mammoth;
import com.google.common.base.Joiner;
-import com.google.common.collect.ImmutableBiMap;
-import com.google.common.collect.ImmutableMap;
import org.zwobble.mammoth.documents.*;
import org.zwobble.mammoth.docx.BodyXmlReader;
import org.zwobble.mammoth.docx.DocumentXmlReader;
import org.zwobble.mammoth.docx.OfficeXml;
import org.zwobble.mammoth.docx.Styles;
import org.zwobble.mammoth.xml.XmlElement;
-import org.zwobble.mammoth.xml.parsing.XmlParser;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -25,7 +21,7 @@ public class Mammoth {
ZipEntry entry = zipFile.getEntry("word/document.xml");
XmlElement documentXml = OfficeXml.parseXml(zipFile.getInputStream(entry));
- Styles styles = new Styles(ImmutableMap.of(), ImmutableMap.of());
+ Styles styles = Styles.EMPTY;
Document document = new DocumentXmlReader(new BodyXmlReader(styles)).readElement(documentXml);
return convertToHtml(document);
} catch (IOException e) {
diff --git a/src/main/java/org/zwobble/mammoth/docx/Styles.java b/src/main/java/org/zwobble/mammoth/docx/Styles.java
index 3ee7372..8784ee2 100644
--- a/src/main/java/org/zwobble/mammoth/docx/Styles.java
+++ b/src/main/java/org/zwobble/mammoth/docx/Styles.java
@@ -1,13 +1,14 @@
package org.zwobble.mammoth.docx;
-import com.google.common.collect.ImmutableMap;
import org.zwobble.mammoth.documents.Style;
import java.util.Map;
import java.util.Optional;
+import static org.zwobble.mammoth.util.MammothMaps.map;
+
public class Styles {
- public static final Styles EMPTY = new Styles(ImmutableMap.of(), ImmutableMap.of());
+ public static final Styles EMPTY = new Styles(map(), map());
private final Map<String, Style> paragraphStyles;
private final Map<String, Style> characterStyles;
diff --git a/src/main/java/org/zwobble/mammoth/util/MammothMaps.java b/src/main/java/org/zwobble/mammoth/util/MammothMaps.java
index 6e988dd..782bd91 100644
--- a/src/main/java/org/zwobble/mammoth/util/MammothMaps.java
+++ b/src/main/java/org/zwobble/mammoth/util/MammothMaps.java
@@ -6,6 +6,22 @@ import java.util.Map;
import java.util.function.Function;
public class MammothMaps {
+ public static <K, V> Map<K, V> map() {
+ return ImmutableMap.of();
+ }
+
+ public static <K, V> Map<K, V> map(K key1, V value1) {
+ return ImmutableMap.of(key1, value1);
+ }
+
+ public static <K, V> Map<K, V> map(K key1, V value1, K key2, V value2) {
+ return ImmutableMap.of(key1, value1, key2, value2);
+ }
+
+ public static <K, V> Map<K, V> map(K key1, V value1, K key2, V value2, K key3, V value3) {
+ return ImmutableMap.of(key1, value1, key2, value2, key3, value3);
+ }
+
public static <T, K, V> Map<K, V> toMap(Iterable<T> iterable, Function<T, Map.Entry<K, V>> function) {
ImmutableMap.Builder<K, V> builder = ImmutableMap.builder();
for (T element : iterable) {
diff --git a/src/main/java/org/zwobble/mammoth/xml/XmlElement.java b/src/main/java/org/zwobble/mammoth/xml/XmlElement.java
index f592415..c44b7bb 100644
--- a/src/main/java/org/zwobble/mammoth/xml/XmlElement.java
+++ b/src/main/java/org/zwobble/mammoth/xml/XmlElement.java
@@ -2,17 +2,17 @@ package org.zwobble.mammoth.xml;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static com.google.common.collect.Iterables.*;
+import static org.zwobble.mammoth.util.MammothMaps.map;
public class XmlElement implements XmlNode, XmlElementLike {
public XmlElement(String name) {
- this(name, ImmutableMap.of());
+ this(name, map());
}
public XmlElement(String name, Map<String, String> attributes) {
diff --git a/src/main/java/org/zwobble/mammoth/xml/XmlNodes.java b/src/main/java/org/zwobble/mammoth/xml/XmlNodes.java
index d168fa6..9531f17 100644
--- a/src/main/java/org/zwobble/mammoth/xml/XmlNodes.java
+++ b/src/main/java/org/zwobble/mammoth/xml/XmlNodes.java
@@ -6,6 +6,8 @@ import com.google.common.collect.ImmutableMap;
import java.util.List;
import java.util.Map;
+import static org.zwobble.mammoth.util.MammothMaps.map;
+
public class XmlNodes {
public static XmlElement element(String name) {
return element(name, ImmutableList.of());
@@ -16,7 +18,7 @@ public class XmlNodes {
}
public static XmlElement element(String name, List<XmlNode> children) {
- return element(name, ImmutableMap.of(), children);
+ return element(name, map(), children);
}
public static XmlElement element(String name, Map<String, String> attributes, List<XmlNode> children) {