aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/mammoth/styles/RunMatcher.java
blob: 75e883c9f85fd1e213d765e15d88906dc73e1ffd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package org.zwobble.mammoth.styles;

import org.zwobble.mammoth.documents.Run;

import java.util.Optional;

public class RunMatcher implements DocumentElementMatcher<Run> {
    public static RunMatcher styleId(String styleId) {
        return new RunMatcher(Optional.of(styleId), Optional.empty());
    }

    public static RunMatcher styleName(String styleName) {
        return new RunMatcher(Optional.empty(), Optional.of(styleName));
    }

    private final Optional<String> styleId;
    private final Optional<String> styleName;

    public RunMatcher(Optional<String> styleId, Optional<String> styleName) {
        this.styleId = styleId;
        this.styleName = styleName;
    }

    @Override
    public boolean matches(Run run) {
        return DocumentElementMatching.matchesStyle(styleId, styleName, run.getStyle());
    }
}