public Iterator<E> iterator()
    {
        // Iterate over the requeue till exhausted. Then start pulling stuff off the queue and putting it onto the
        // requeue, until exhausted.
        return new Iterator<E>()
            {
                Iterator<RequeueElementWrapper<E>> requeueIterator = requeue.iterator();
                boolean usingRequeue = true;

                public boolean hasNext()
                {
                    boolean result = false;

                    if (usingRequeue)
                    {
                        result = requeueIterator.hasNext();

                        if (!result)
                        {
                            usingRequeue = false;
                        }
                    }

                    if (!usingRequeue)
                    {
                        result = !queue.isEmpty();
                    }

                    return result;
                }

                public E next()
                {
                    E result;

                    if (usingRequeue)
                    {
                        result = requeueIterator.next().element;
                    }
                    else
                    {
                        result = queue.poll();
                        requeue(result);
                    }

                    return result;
                }

                public void remove()
                {
                    throw new NotImplementedException();
                }
            };
    }
public Iterator < E > iterator ( ) { return new Iterator < E > ( ) { Iterator < RequeueElementWrapper < E > > requeueIterator = requeue . iterator ( ) ; boolean usingRequeue = true ; public boolean hasNext ( ) { boolean result = false ; if ( usingRequeue ) { result = requeueIterator . hasNext ( ) ; if ( ! result ) { usingRequeue = false ; } } if ( ! usingRequeue ) { result = ! queue . isEmpty ( ) ; } return result ; } public E next ( ) { E result ; if ( usingRequeue ) { result = requeueIterator . next ( ) . element ; } else { result = queue . poll ( ) ; requeue ( result ) ; } return result ; } public void remove ( ) { throw new NotImplementedException ( ) ; } } ; }
{@inheritDoc}