From 8377b89bfc97a85dbe90fb4cfa5dd33cd3568af4 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 21 Feb 2016 10:09:47 +0000 Subject: Add style mappings for runs --- .../zwobble/mammoth/styles/ParagraphMatcher.java | 23 ++++++---------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'src/main/java/org/zwobble/mammoth/styles/ParagraphMatcher.java') diff --git a/src/main/java/org/zwobble/mammoth/styles/ParagraphMatcher.java b/src/main/java/org/zwobble/mammoth/styles/ParagraphMatcher.java index 5ce1512..395a20b 100644 --- a/src/main/java/org/zwobble/mammoth/styles/ParagraphMatcher.java +++ b/src/main/java/org/zwobble/mammoth/styles/ParagraphMatcher.java @@ -2,12 +2,10 @@ package org.zwobble.mammoth.styles; import org.zwobble.mammoth.documents.NumberingLevel; import org.zwobble.mammoth.documents.Paragraph; -import org.zwobble.mammoth.documents.Style; import java.util.Optional; -import java.util.function.BiPredicate; -public class ParagraphMatcher { +public class ParagraphMatcher implements DocumentElementMatcher { public static final ParagraphMatcher ANY = new ParagraphMatcher(Optional.empty(), Optional.empty(), Optional.empty()); public static ParagraphMatcher styleId(String styleId) { @@ -36,26 +34,17 @@ public class ParagraphMatcher { this.numbering = numbering; } + @Override public boolean matches(Paragraph paragraph) { - return matchesStyleId(paragraph) && matchesStyleName(paragraph) && matchesNumbering(paragraph); + return matchesStyle(paragraph) && matchesNumbering(paragraph); } - private boolean matchesStyleId(Paragraph paragraph) { - return matches(styleId, paragraph.getStyle().map(Style::getStyleId), Object::equals); - } - - private boolean matchesStyleName(Paragraph paragraph) { - return matches(styleName, paragraph.getStyle().flatMap(Style::getName), String::equalsIgnoreCase); + private boolean matchesStyle(Paragraph paragraph) { + return DocumentElementMatching.matchesStyle(styleId, styleName, paragraph.getStyle()); } private boolean matchesNumbering(Paragraph paragraph) { - return matches(numbering, paragraph.getNumbering(), (first, second) -> + return DocumentElementMatching.matches(numbering, paragraph.getNumbering(), (first, second) -> first.isOrdered() == second.isOrdered() && first.getLevelIndex().equalsIgnoreCase(second.getLevelIndex())); } - - private boolean matches(Optional required, Optional actual, BiPredicate areEqual) { - return required - .map(requiredValue -> actual.map(actualValue -> areEqual.test(requiredValue, actualValue)).orElse(false)) - .orElse(true); - } } -- cgit v1.2.3