public Iterator iterator()

in src/main/java/org/apache/commons/graph/coloring/UncoloredOrderedVertices.java [62:110]


    public Iterator<V> iterator()
    {
        return new Iterator<V>()
        {

            private Iterator<Integer> keys = orderedVertices.keySet().iterator();

            private Iterator<V> pending = null;

            private V next = null;

            public boolean hasNext()
            {
                if ( next != null )
                {
                    return true;
                }

                while ( ( pending == null ) || !pending.hasNext() )
                {
                    if ( !keys.hasNext() )
                    {
                        return false;
                    }
                    pending = orderedVertices.get( keys.next() ).iterator();
                }

                next = pending.next();
                return true;
            }

            public V next()
            {
                if ( !hasNext() )
                {
                    throw new NoSuchElementException();
                }
                V returned = next;
                next = null;
                return returned;
            }

            public void remove()
            {
                pending.remove();
            }

        };
    }