class OctantIterator implements Iterator<NodeModel> {

        private final boolean ignoreVisibility;
        private int leafId;
        private Octant octant;
        private int leavesLength;
        private NodeModel[] nodes;
        private int nodesId;
        private int nodesLength;
        private NodeModel pointer;

        public OctantIterator(boolean ignoreVisibility) {
            leavesLength = leaves.length;
            this.ignoreVisibility = ignoreVisibility;
        }

        @Override
        public boolean hasNext() {<FILL_FUNCTION_BODY>}

        @Override
        public NodeModel next() {
            return pointer;
        }

        public void reset() {
            leafId = 0;
            octant = null;
            leavesLength = leaves.length;
            nodes = null;
            nodesId = 0;
            nodesLength = 0;
            pointer = null;
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException("Not supported.");
        }
    }

            pointer = null;
            while (pointer == null) {
                while (nodesId < nodesLength && pointer == null) {
                    pointer = nodes[nodesId++];
                }
                if (pointer == null) {
                    octant = null;
                    while (leafId < leavesLength && (octant == null || (!octant.visible && !ignoreVisibility))) {
                        octant = leaves[leafId++];
                    }
                    if (octant == null || (!octant.visible && !ignoreVisibility)) {
                        return false;
                    }
                    nodes = octant.nodes;
                    nodesId = 0;
                    nodesLength = octant.nodesLength;
                }
            }
            return pointer != null;
        
<no_super_class>