blob: bfd3fc363a90a9d3729e4f6771a6bddcac25ed9f (
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
29
30
31
32
33
34
|
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;
private final Map<String, List<String>> targetsByType;
public Relationships(List<Relationship> relationships) {
this.targetsByRelationshipId = toMap(relationships, relationship -> entry(
relationship.getRelationshipId(),
relationship.getTarget()
));
this.targetsByType = toMultiMap(relationships, relationship -> entry(
relationship.getType(),
relationship.getTarget()
));
}
public String findTargetByRelationshipId(String relationshipId) {
return lookup(targetsByRelationshipId, relationshipId)
.orElseThrow(() -> new RuntimeException("Could not find relationship '" + relationshipId + "'"));
}
public List<String> findTargetsByType(String type) {
return lookup(targetsByType, type).orElse(list());
}
}
|