From 8d07fccc0787bb043125e2f8788e550c692a2579 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 13 Nov 2016 12:38:05 +0000 Subject: Read embedded style maps --- .../zwobble/mammoth/internal/styles/StyleMap.java | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/main/java/org/zwobble/mammoth/internal/styles/StyleMap.java') diff --git a/src/main/java/org/zwobble/mammoth/internal/styles/StyleMap.java b/src/main/java/org/zwobble/mammoth/internal/styles/StyleMap.java index c587483..f2222a9 100644 --- a/src/main/java/org/zwobble/mammoth/internal/styles/StyleMap.java +++ b/src/main/java/org/zwobble/mammoth/internal/styles/StyleMap.java @@ -15,6 +15,18 @@ public class StyleMap { return new StyleMapBuilder(); } + public static StyleMap merge(StyleMap high, StyleMap low) { + // TODO: add appropriate tests + return new StyleMap( + Optionals.first(high.bold, low.bold), + Optionals.first(high.italic, low.italic), + Optionals.first(high.underline, low.underline), + Optionals.first(high.strikethrough, low.strikethrough), + Optionals.first(high.commentReference, low.commentReference), + Lists.eagerConcat(high.paragraphStyles, low.paragraphStyles), + Lists.eagerConcat(high.runStyles, low.runStyles)); + } + public static final StyleMap EMPTY = new StyleMapBuilder().build(); private final Optional bold; @@ -45,14 +57,7 @@ public class StyleMap { public StyleMap update(StyleMap styleMap) { // TODO: add appropriate tests - return new StyleMap( - Optionals.first(styleMap.bold, bold), - Optionals.first(styleMap.italic, italic), - Optionals.first(styleMap.underline, underline), - Optionals.first(styleMap.strikethrough, strikethrough), - Optionals.first(styleMap.commentReference, commentReference), - Lists.eagerConcat(styleMap.paragraphStyles, paragraphStyles), - Lists.eagerConcat(styleMap.runStyles, runStyles)); + return merge(styleMap, this); } public Optional getBold() { -- cgit v1.2.3