filter method
List<TreeReference>
filter(
- DataInstance sourceInstance,
- TreeReference nodeset,
- XPathExpression predicate,
- List<
TreeReference> children, - EvaluationContext context,
- List<
TreeReference> next(),
override
The children of nodeset that pass predicate, or the result of
next (the rest of the chain) when this strategy doesn't apply.
Implementation
@override
List<TreeReference> filter(
DataInstance sourceInstance,
TreeReference nodeset,
XPathExpression predicate,
List<TreeReference> children,
EvaluationContext context,
List<TreeReference> Function() next,
) {
if (sourceInstance.instanceId == null || predicate is! XPathEqExpr) {
return next();
}
final candidate = CompareToNodeExpression.parse(predicate);
if (candidate == null || !predicate.equal) return next();
final section = '$nodeset${candidate.nodeSide}';
final sectionIndex = _index.putIfAbsent(section, () {
final built = <String, List<TreeReference>>{};
for (var i = 0; i < children.length; i++) {
Measure.log('IndexEvaluation');
final value = _javaToString(
candidate.evalNodeSide(sourceInstance, context, children[i], i),
);
(built[value] ??= []).add(children[i]);
}
return built;
});
final absoluteValue = candidate.evalContextSide(sourceInstance, context);
if (absoluteValue is! String) return next();
return sectionIndex[absoluteValue] ?? const [];
}