2020-05-17 09:48:24 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-02-17 11:24:50 +02:00
|
|
|
import BNote = require("../../becca/entities/bnote");
|
|
|
|
|
2020-05-17 09:48:24 +02:00
|
|
|
class NoteSet {
|
2024-02-17 11:24:50 +02:00
|
|
|
|
|
|
|
private notes: BNote[];
|
|
|
|
private noteIdSet: Set<string>;
|
|
|
|
private sorted: boolean;
|
|
|
|
|
|
|
|
constructor(notes: BNote[] = []) {
|
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
|
|
|
this.sorted = false;
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
2024-02-17 11:24:50 +02:00
|
|
|
add(note: BNote) {
|
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
|
|
|
}
|
|
|
|
|
2024-02-17 11:24:50 +02:00
|
|
|
addAll(notes: BNote[]) {
|
2020-05-23 10:25:22 +02:00
|
|
|
for (const note of notes) {
|
|
|
|
this.add(note);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-17 11:24:50 +02:00
|
|
|
hasNote(note: BNote) {
|
2020-05-23 10:25:22 +02:00
|
|
|
return this.hasNoteId(note.noteId);
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
2024-02-17 11:24:50 +02:00
|
|
|
hasNoteId(noteId: string) {
|
2020-08-28 23:20:22 +02:00
|
|
|
return this.noteIdSet.has(noteId);
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
2024-02-17 11:24:50 +02:00
|
|
|
mergeIn(anotherNoteSet: NoteSet) {
|
2023-10-24 23:10:52 +02:00
|
|
|
this.addAll(anotherNoteSet.notes);
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
2020-05-17 19:43:37 +02:00
|
|
|
|
2024-02-17 11:24:50 +02:00
|
|
|
minus(anotherNoteSet: NoteSet) {
|
2020-05-17 19:43:37 +02:00
|
|
|
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
|
|
|
|
2024-02-17 11:24:50 +02:00
|
|
|
intersection(anotherNoteSet: NoteSet) {
|
2020-05-23 12:27:44 +02:00
|
|
|
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
|
|
|
|
2024-02-17 00:44:44 +02:00
|
|
|
export = NoteSet;
|