use of org.apache.commons.jexl2.parser.JexlNodes.newInstanceOfType in project datawave by NationalSecurityAgency.
the class TreeFlatteningRebuilder method rebuildNode.
/**
* Returns a copy of the passed in node.
*
* If the original node has children, those exact children (not copies) will be added to the copied node. However, the parentage of those child nodes will
* be left as-is.
*
* If the original node has no children, we will simply use the RebuildingVisitor to copy the node.
*
* @param node
* the node to copy
* @return the copied node
*/
private JexlNode rebuildNode(JexlNode node) {
JexlNode newNode;
if (node.jjtGetNumChildren() == 0) {
newNode = RebuildingVisitor.copy(node);
} else {
newNode = JexlNodes.newInstanceOfType(node);
newNode.image = node.image;
JexlNodes.ensureCapacity(newNode, node.jjtGetNumChildren());
int nodeIdx = 0;
for (JexlNode child : children(node)) newNode.jjtAddChild(child, nodeIdx++);
}
return newNode;
}
use of org.apache.commons.jexl2.parser.JexlNodes.newInstanceOfType in project datawave by NationalSecurityAgency.
the class PushdownMissingIndexRangeNodesVisitor method visit.
@Override
public Object visit(ASTAndNode node, Object data) {
LiteralRange range = JexlASTHelper.findRange().indexedOnly(this.dataTypeFilter, this.helper).notDelayed().getRange(node);
if (range != null) {
return delayBoundedIndexHole(range, node, data);
} else {
JexlNode andNode = JexlNodes.newInstanceOfType(node);
andNode.image = node.image;
andNode.jjtSetParent(node.jjtGetParent());
// We have no bounded range to replace, just proceed as normal
JexlNodes.ensureCapacity(andNode, node.jjtGetNumChildren());
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
JexlNode newChild = (JexlNode) node.jjtGetChild(i).jjtAccept(this, data);
andNode.jjtAddChild(newChild, i);
newChild.jjtSetParent(andNode);
}
return andNode;
}
}
use of org.apache.commons.jexl2.parser.JexlNodes.newInstanceOfType in project datawave by NationalSecurityAgency.
the class UniqueExpressionTermsVisitor method removeDuplicateNodes.
private JexlNode removeDuplicateNodes(JexlNode node, Object data) {
// Traverse each child to de-dupe their children.
// @formatter:off
List<JexlNode> visitedChildren = Arrays.stream(children(node)).map(child -> (JexlNode) child.jjtAccept(this, data)).filter(Objects::nonNull).collect(Collectors.toList());
// @formatter:on
// Dedupe the visited children.
List<JexlNode> uniqueChildren = getUniqueChildren(visitedChildren);
if (uniqueChildren.size() == 1) {
// If only one child remains, return it.
return uniqueChildren.get(0);
} else {
// If two or more children remain, return a copy with the unique children.
JexlNode copy = JexlNodes.newInstanceOfType(node);
copy.image = node.image;
copy.jjtSetParent(node.jjtGetParent());
JexlNodes.children(copy, uniqueChildren.toArray(new JexlNode[0]));
return copy;
}
}
Aggregations