private boolean accept(
        List<String> globComponents,
        int componentIndex,
        MetadataNode node,
        String[] path
    ) {
        if (componentIndex >= globComponents.size()) {
            handler.accept(Optional.of(new MetadataNodeInfo(path, node)));
            return true;
        }
        String globComponentString = globComponents.get(componentIndex);
        GlobComponent globComponent = new GlobComponent(globComponentString);
        if (globComponent.literal()) {
            if (!node.isDirectory()) {
                return false;
            }
            MetadataNode child = node.child(globComponent.component());
            if (child == null) {
                return false;
            }
            String[] newPath = new String[path.length + 1];
            System.arraycopy(path, 0, newPath, 0, path.length);
            newPath[path.length] = globComponent.component();
            return accept(globComponents, componentIndex + 1, child, newPath);
        }
        if (!node.isDirectory()) {
            return false;
        }
        boolean matchedAny = false;
        ArrayList<String> nodeChildNames = new ArrayList<>(node.childNames());
        nodeChildNames.sort(String::compareTo);
        for (String nodeName : nodeChildNames) {
            if (globComponent.matches(nodeName)) {
                String[] newPath = new String[path.length + 1];
                System.arraycopy(path, 0, newPath, 0, path.length);
                newPath[path.length] = nodeName;
                MetadataNode child = node.child(nodeName);
                if (child == null) {
                    throw new RuntimeException("Expected " + nodeName + " to be a valid child of " +
                            node.getClass() + ", but it was not.");
                }
                if (accept(globComponents, componentIndex + 1, child, newPath)) {
                    matchedAny = true;
                }
            }
        }
        return matchedAny;
    }
Visits metadata paths based on a glob string.
shell/src/main/java/org/apache/kafka/shell/glob/GlobVisitor.java