2020-05-23 10:36:49 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Expression = require('./expression');
|
|
|
|
const NoteSet = require('../note_set');
|
|
|
|
|
|
|
|
class ParentOfExp extends Expression {
|
|
|
|
constructor(subExpression) {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.subExpression = subExpression;
|
|
|
|
}
|
|
|
|
|
2020-12-11 13:54:41 +01:00
|
|
|
execute(inputNoteSet, executionContext) {
|
2020-05-23 10:36:49 +02:00
|
|
|
const subInputNoteSet = new NoteSet();
|
|
|
|
|
|
|
|
for (const note of inputNoteSet.notes) {
|
|
|
|
subInputNoteSet.addAll(note.children);
|
|
|
|
}
|
|
|
|
|
2020-12-11 13:54:41 +01:00
|
|
|
const subResNoteSet = this.subExpression.execute(subInputNoteSet, executionContext);
|
2020-05-23 10:36:49 +02:00
|
|
|
|
|
|
|
const resNoteSet = new NoteSet();
|
|
|
|
|
|
|
|
for (const childNote of subResNoteSet.notes) {
|
|
|
|
for (const parentNote of childNote.parents) {
|
|
|
|
if (inputNoteSet.hasNote(parentNote)) {
|
|
|
|
resNoteSet.add(parentNote);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return resNoteSet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ParentOfExp;
|