package org.zwobble.mammoth.internal.documents; import java.util.List; import java.util.Map; import java.util.Optional; import static org.zwobble.mammoth.internal.util.MammothLists.list; import static org.zwobble.mammoth.internal.util.MammothMaps.*; public class Notes { public final static Notes EMPTY = new Notes(list()); private final Map> notes; public Notes(List notes) { this.notes = eagerMapValues( toMultiMapWithKey(notes, Note::getNoteType), notesOfType -> toMapWithKey(notesOfType, Note::getId)); } public Optional findNote(NoteType noteType, String noteId) { return lookup(notes, noteType) .flatMap(notesOfType -> lookup(notesOfType, noteId)); } }