blob: 2959bb014614cf846031cb53944fb90b97823a26 (
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
|
package org.zwobble.mammoth.documents;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimaps;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.zwobble.mammoth.util.MammothLists.list;
public class Notes {
public final static Notes EMPTY = new Notes(list());
private final Map<NoteType, Map<String, Note>> notes;
public Notes(List<Note> notes) {
this.notes = Maps.transformValues(
Multimaps.index(notes, Note::getNoteType).asMap(),
notesOfType -> Maps.uniqueIndex(notesOfType, Note::getId));
}
public Optional<Note> findNote(NoteType noteType, String noteId) {
return Optional.ofNullable(notes.get(noteType))
.flatMap(notesOfType -> Optional.ofNullable(notesOfType.get(noteId)));
}
}
|