aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble/mammoth/internal/docx/Relationships.java
blob: d4d6f2e8006b7e5ac5cb9c2a68cb5d89fd2d222f (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
package org.zwobble.mammoth.internal.docx;

import java.util.List;
import java.util.Map;

import static org.zwobble.mammoth.internal.util.Lists.list;
import static org.zwobble.mammoth.internal.util.Maps.*;

public class Relationships {
    public static final Relationships EMPTY = new Relationships(list());

    private final Map<String, String> targetsByRelationshipId;

    public Relationships(List<Relationship> relationships) {
        this.targetsByRelationshipId = toMap(relationships, relationship -> entry(
            relationship.getRelationshipId(),
            relationship.getTarget()
        ));
    }

    public String findTargetByRelationshipId(String relationshipId) {
        return lookup(targetsByRelationshipId, relationshipId)
            .orElseThrow(() -> new RuntimeException("Could not find relationship '" + relationshipId + "'"));
    }
}