JcrChildNodeIterator implements NodeIterator { @Override public long getSize() { if (size > -1L) return size; if (!hasNext()) { size = resolvedNode == null ? ndx : ndx + 1; return size; } List<Node> remainingNodes = new LinkedList<>(); if (resolvedNode != null) { size = ndx + 1; remainingNodes.add(resolvedNode); resolvedNode = null; } else { size = ndx; } while (iterator.hasNext()) { Node node = resolver.nodeFrom(iterator.next()); if (node != null) { remainingNodes.add(node); ++size; } } nodeIterator = remainingNodes.iterator(); return size; } JcrChildNodeIterator( NodeResolver resolver,
                          Iterator<ChildReference> iterator );   JcrChildNodeIterator( NodeResolver resolver,
                          ChildReferences childReferences ); @Override long getPosition(); @Override long getSize(); @Override boolean hasNext(); @Override Object next(); @Override Node nextNode(); @Override void remove(); @Override void skip( long count );  }
@Test public void shouldHaveCorrectSize() { assertThat(iter.getSize(), is((long)children.size())); }