aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/mammoth/styles/DocumentElementMatching.java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-02-21 10:09:47 +0000
committerMichael Williamson <mike@zwobble.org>2016-02-21 10:09:47 +0000
commit8377b89bfc97a85dbe90fb4cfa5dd33cd3568af4 (patch)
treec37ec926bfb9cf2c45ebfb564edb596fa1e0965a /src/main/java/org/zwobble/mammoth/styles/DocumentElementMatching.java
parentc1604e510cc831a00f6105df35c68a856f061b65 (diff)
Add style mappings for runs
Diffstat (limited to 'src/main/java/org/zwobble/mammoth/styles/DocumentElementMatching.java')
-rw-r--r--src/main/java/org/zwobble/mammoth/styles/DocumentElementMatching.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/mammoth/styles/DocumentElementMatching.java b/src/main/java/org/zwobble/mammoth/styles/DocumentElementMatching.java
new file mode 100644
index 0000000..0ed00fc
--- /dev/null
+++ b/src/main/java/org/zwobble/mammoth/styles/DocumentElementMatching.java
@@ -0,0 +1,26 @@
+package org.zwobble.mammoth.styles;
+
+import org.zwobble.mammoth.documents.Style;
+
+import java.util.Optional;
+import java.util.function.BiPredicate;
+
+class DocumentElementMatching {
+ static boolean matchesStyle(Optional<String> styleId, Optional<String> styleName, Optional<Style> style) {
+ return matchesStyleId(styleId, style) && matchesStyleName(styleName, style);
+ }
+
+ private static boolean matchesStyleId(Optional<String> styleId, Optional<Style> style) {
+ return matches(styleId, style.map(Style::getStyleId), Object::equals);
+ }
+
+ private static boolean matchesStyleName(Optional<String> styleName, Optional<Style> style) {
+ return matches(styleName, style.flatMap(Style::getName), String::equalsIgnoreCase);
+ }
+
+ static <T> boolean matches(Optional<T> required, Optional<T> actual, BiPredicate<T, T> areEqual) {
+ return required
+ .map(requiredValue -> actual.map(actualValue -> areEqual.test(requiredValue, actualValue)).orElse(false))
+ .orElse(true);
+ }
+}