2020-05-17 09:48:24 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
class NoteSet {
|
2020-05-16 23:12:29 +02:00
|
|
|
constructor(notes = []) {
|
|
|
|
this.notes = notes;
|
|
|
|
}
|
|
|
|
|
|
|
|
add(note) {
|
|
|
|
this.notes.push(note);
|
|
|
|
}
|
|
|
|
|
|
|
|
addAll(notes) {
|
|
|
|
this.notes.push(...notes);
|
|
|
|
}
|
|
|
|
|
|
|
|
hasNoteId(noteId) {
|
|
|
|
// TODO: optimize
|
|
|
|
return !!this.notes.find(note => note.noteId === noteId);
|
|
|
|
}
|
|
|
|
|
|
|
|
mergeIn(anotherNoteSet) {
|
2020-05-22 19:08:06 +02:00
|
|
|
this.notes = this.notes.concat(anotherNoteSet.notes);
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
2020-05-17 19:43:37 +02:00
|
|
|
|
|
|
|
minus(anotherNoteSet) {
|
|
|
|
const newNoteSet = new NoteSet();
|
|
|
|
|
|
|
|
for (const note of this.notes) {
|
|
|
|
if (!anotherNoteSet.hasNoteId(note.noteId)) {
|
|
|
|
newNoteSet.add(note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newNoteSet;
|
|
|
|
}
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
2020-05-17 09:48:24 +02:00
|
|
|
|
|
|
|
module.exports = NoteSet;
|