diff options
Diffstat (limited to 'src/main/java/org/zwobble/mammoth/documents')
3 files changed, 45 insertions, 2 deletions
diff --git a/src/main/java/org/zwobble/mammoth/documents/Document.java b/src/main/java/org/zwobble/mammoth/documents/Document.java index 4d91925..c3a14d3 100644 --- a/src/main/java/org/zwobble/mammoth/documents/Document.java +++ b/src/main/java/org/zwobble/mammoth/documents/Document.java @@ -4,12 +4,18 @@ import java.util.List; public class Document implements HasChildren { private final List<DocumentElement> children; + private final Notes notes; - public Document(List<DocumentElement> children) { + public Document(List<DocumentElement> children, Notes notes) { this.children = children; + this.notes = notes; } public List<DocumentElement> getChildren() { return children; } + + public Notes getNotes() { + return notes; + } } diff --git a/src/main/java/org/zwobble/mammoth/documents/Note.java b/src/main/java/org/zwobble/mammoth/documents/Note.java index 1a0d3c0..da6f68f 100644 --- a/src/main/java/org/zwobble/mammoth/documents/Note.java +++ b/src/main/java/org/zwobble/mammoth/documents/Note.java @@ -3,11 +3,21 @@ package org.zwobble.mammoth.documents; import java.util.List; public class Note { + private final NoteType noteType; private final String id; private final List<DocumentElement> body; - public Note(String id, List<DocumentElement> body) { + public Note(NoteType noteType, String id, List<DocumentElement> body) { + this.noteType = noteType; this.id = id; this.body = body; } + + public NoteType getNoteType() { + return noteType; + } + + public String getId() { + return id; + } } diff --git a/src/main/java/org/zwobble/mammoth/documents/Notes.java b/src/main/java/org/zwobble/mammoth/documents/Notes.java new file mode 100644 index 0000000..2959bb0 --- /dev/null +++ b/src/main/java/org/zwobble/mammoth/documents/Notes.java @@ -0,0 +1,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))); + } +} |
