2020-05-17 09:48:24 +02:00
|
|
|
"use strict";
|
|
|
|
|
2024-07-18 21:35:17 +03:00
|
|
|
import NoteSet from "../note_set.js";
|
|
|
|
import SearchContext from "../search_context.js";
|
|
|
|
import Expression from "./expression.js";
|
|
|
|
import TrueExp from "./true.js";
|
2020-05-22 09:38:30 +02:00
|
|
|
|
2020-05-23 10:25:22 +02:00
|
|
|
class AndExp extends Expression {
|
2025-01-10 21:20:46 +02:00
|
|
|
subExpressions: Expression[];
|
2024-02-18 00:43:55 +02:00
|
|
|
|
2024-02-18 02:27:04 +02:00
|
|
|
static of(_subExpressions: (Expression | null | undefined)[]) {
|
|
|
|
const subExpressions = _subExpressions.filter((exp) => !!exp) as Expression[];
|
2020-05-20 23:20:39 +02:00
|
|
|
|
2020-05-19 00:00:35 +02:00
|
|
|
if (subExpressions.length === 1) {
|
|
|
|
return subExpressions[0];
|
2020-05-20 23:20:39 +02:00
|
|
|
} else if (subExpressions.length > 0) {
|
2020-05-19 00:00:35 +02:00
|
|
|
return new AndExp(subExpressions);
|
2021-04-22 20:28:26 +02:00
|
|
|
} else {
|
|
|
|
return new TrueExp();
|
2020-05-19 00:00:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-18 00:43:55 +02:00
|
|
|
constructor(subExpressions: Expression[]) {
|
2020-05-22 09:38:30 +02:00
|
|
|
super();
|
2020-05-20 23:20:39 +02:00
|
|
|
this.subExpressions = subExpressions;
|
|
|
|
}
|
|
|
|
|
2024-02-18 00:43:55 +02:00
|
|
|
execute(inputNoteSet: NoteSet, executionContext: {}, searchContext: SearchContext) {
|
2020-05-16 23:12:29 +02:00
|
|
|
for (const subExpression of this.subExpressions) {
|
2022-12-17 13:07:42 +01:00
|
|
|
inputNoteSet = subExpression.execute(inputNoteSet, executionContext, searchContext);
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
|
2020-05-23 12:27:44 +02:00
|
|
|
return inputNoteSet;
|
2020-05-16 23:12:29 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-17 09:48:24 +02:00
|
|
|
|
2024-07-18 21:50:12 +03:00
|
|
|
export default AndExp;
|