2020-05-17 09:48:24 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
class NoteSet {
|
2020-05-16 23:12:29 +02:00
|
|
|
constructor(notes = []) {
|
2020-05-23 23:44:55 +02:00
|
|
|
/** @type {Note[]} */
|
2020-05-16 23:12:29 +02:00
|
|
|
this.notes = notes;
|
2020-08-28 23:20:22 +02:00
|
|
|
this.noteIdSet = new Set(notes.map(note => note.noteId));
|
2020-05-25 00:25:47 +02:00
|
|
|
/** @type {boolean} */
|
|
|
|
this.sorted = false;
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
add(note) {
|
2020-05-23 10:25:22 +02:00
|
|
|
if (!this.hasNote(note)) {
|
|
|
|
this.notes.push(note);
|
2020-08-28 23:20:22 +02:00
|
|
|
this.noteIdSet.add(note.noteId);
|
2020-05-23 10:25:22 +02:00
|
|
|
}
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
addAll(notes) {
|
2020-05-23 10:25:22 +02:00
|
|
|
for (const note of notes) {
|
|
|
|
this.add(note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
hasNote(note) {
|
|
|
|
return this.hasNoteId(note.noteId);
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hasNoteId(noteId) {
|
2020-08-28 23:20:22 +02:00
|
|
|
return this.noteIdSet.has(noteId);
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
mergeIn(anotherNoteSet) {
|
2020-09-23 22:27:19 +02:00
|
|
|
for (const note of anotherNoteSet.notes) {
|
|
|
|
if (!this.noteIdSet.has(note.noteId)) {
|
|
|
|
this.noteIdSet.add(note.noteId);
|
|
|
|
this.notes.push(note);
|
|
|
|
}
|
|
|
|
}
|
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-23 12:27:44 +02:00
|
|
|
|
|
|
|
intersection(anotherNoteSet) {
|
|
|
|
const newNoteSet = new NoteSet();
|
|
|
|
|
|
|
|
for (const note of this.notes) {
|
|
|
|
if (anotherNoteSet.hasNote(note)) {
|
|
|
|
newNoteSet.add(note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newNoteSet;
|
|
|
|
}
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
2020-05-17 09:48:24 +02:00
|
|
|
|
|
|
|
module.exports = NoteSet;
|