2020-05-17 09:48:24 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
2024-07-18 21:35:17 +03:00
|
|
|
import Expression from "./expression.js";
|
|
|
|
|
import NoteSet from "../note_set.js";
|
|
|
|
|
import TrueExp from "./true.js";
|
|
|
|
|
import SearchContext from "../search_context.js";
|
2020-05-19 00:00:35 +02:00
|
|
|
|
2020-05-22 09:38:30 +02:00
|
|
|
class OrExp extends Expression {
|
2024-02-18 01:06:42 +02:00
|
|
|
private subExpressions: Expression[];
|
|
|
|
|
|
|
|
|
|
static of(subExpressions: Expression[]) {
|
2020-05-20 23:20:39 +02:00
|
|
|
subExpressions = subExpressions.filter(exp => !!exp);
|
|
|
|
|
|
|
|
|
|
if (subExpressions.length === 1) {
|
|
|
|
|
return subExpressions[0];
|
|
|
|
|
}
|
|
|
|
|
else if (subExpressions.length > 0) {
|
|
|
|
|
return new OrExp(subExpressions);
|
|
|
|
|
}
|
2021-04-22 20:28:26 +02:00
|
|
|
else {
|
|
|
|
|
return new TrueExp();
|
|
|
|
|
}
|
2020-05-20 23:20:39 +02:00
|
|
|
}
|
|
|
|
|
|
2024-02-18 01:06:42 +02:00
|
|
|
constructor(subExpressions: Expression[]) {
|
2020-05-22 09:38:30 +02:00
|
|
|
super();
|
|
|
|
|
|
2020-05-16 23:12:29 +02:00
|
|
|
this.subExpressions = subExpressions;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-18 01:06:42 +02:00
|
|
|
execute(inputNoteSet: NoteSet, executionContext: {}, searchContext: SearchContext) {
|
2020-05-16 23:12:29 +02:00
|
|
|
const resultNoteSet = new NoteSet();
|
|
|
|
|
|
|
|
|
|
for (const subExpression of this.subExpressions) {
|
2022-12-23 14:02:18 +01:00
|
|
|
resultNoteSet.mergeIn(subExpression.execute(inputNoteSet, executionContext, searchContext));
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultNoteSet;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-17 09:48:24 +02:00
|
|
|
|
2024-02-18 01:06:42 +02:00
|
|
|
export = OrExp;
|