/** * Given a node filter and a node type, find all nodes that match both the filter and the type of the Node. * @param filter is the filter to lookup by. * @param clazz is the class of the node type we want to find. * @return the nodes matching the filter and clazz. */ public <T extends Node> List<T> getMatchingNodesOfType(NodeFilter filter, Class<T> clazz) { Halconfig halconfig = parser.getHalconfig(); return getMatchingNodes(halconfig, filter) .stream() .filter(clazz::isInstance) .map(n -> (T) n) .collect(Collectors.toList()); }
/** * Given a node filter and a node type, find all nodes that match both the filter and the type of the Node. * @param filter is the filter to lookup by. * @param clazz is the class of the node type we want to find. * @return the nodes matching the filter and clazz. */ public <T extends Node> List<T> getMatchingNodesOfType(NodeFilter filter, Class<T> clazz) { Halconfig halconfig = parser.getHalconfig(); return getMatchingNodes(halconfig, filter) .stream() .filter(clazz::isInstance) .map(n -> (T) n) .collect(Collectors.toList()); }
/** * @param node is the node whose children we want to find. * @param filter is the filter to lookup by. * @return the children of the input node matching the filter. */ private List<Node> getMatchingNodes(Node node, NodeFilter filter) { log.trace("Checking for leaf nodes of node " + node.getNodeName()); List<Node> result = new ArrayList<>(); NodeIterator children = node.getChildren(); Node recurse = children.getNext(filter); while (recurse != null) { result.addAll(getMatchingNodes(recurse, filter)); recurse = children.getNext(filter); } // If we have visited this node, it must have matched the filter. result.add(node); return result; }
/** * @param node is the node whose children we want to find. * @param filter is the filter to lookup by. * @return the children of the input node matching the filter. */ private List<Node> getMatchingNodes(Node node, NodeFilter filter) { log.trace("Checking for leaf nodes of node " + node.getNodeName()); List<Node> result = new ArrayList<>(); NodeIterator children = node.getChildren(); Node recurse = children.getNext(filter); while (recurse != null) { result.addAll(getMatchingNodes(recurse, filter)); recurse = children.getNext(filter); } // If we have visited this node, it must have matched the filter. result.add(node); return result; }