public Iterator listChildren()

in src/main/java/org/apache/sling/commons/testing/sling/MockResourceResolver.java [85:128]


    public Iterator<Resource> listChildren(final Resource parent) {
        Collection<Resource> childCollection = children.get(parent.getPath());
        if (childCollection != null) {
            return childCollection.iterator();
        }

        return new Iterator<Resource>() {
            final String parentPath = parent.getPath() + "/";

            final Iterator<Resource> elements = resources.values().iterator();

            Resource nextResource = seek();

            public boolean hasNext() {
                return nextResource != null;
            }

            public Resource next() {
                if (!hasNext()) {
                    throw new NoSuchElementException();
                }

                Resource result = nextResource;
                nextResource = seek();
                return result;
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }

            private Resource seek() {
                while (elements.hasNext()) {
                    Resource next = elements.next();
                    String path = next.getPath();
                    if (path.startsWith(parentPath)
                        && path.indexOf('/', parentPath.length()) < 0) {
                        return next;
                    }
                }
                return null;
            }
        };
    }