@@ -0,0 +1,3281 @@
+//%0A// $Id: CompoundIterator.java,v 1.1 2001/11/20 03:35:53 mdb Exp $%0A//%0A// samskivert library - useful routines for java programs%0A// Copyright (C) 2001 Michael Bayne%0A// %0A// This library is free software; you can redistribute it and/or modify it%0A// under the terms of the GNU Lesser General Public License as published%0A// by the Free Software Foundation; either version 2.1 of the License, or%0A// (at your option) any later version.%0A//%0A// This library is distributed in the hope that it will be useful,%0A// but WITHOUT ANY WARRANTY; without even the implied warranty of%0A// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU%0A// Lesser General Public License for more details.%0A//%0A// You should have received a copy of the GNU Lesser General Public%0A// License along with this library; if not, write to the Free Software%0A// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA%0A%0Apackage com.samskivert.util;%0A%0Aimport java.util.Iterator;%0Aimport java.util.NoSuchElementException;%0A%0A/**%0A * Iterates over a collection of iterators, moving seamlessly from one%0A * iterator to the next as the first runs out of elements. Iterators are%0A * made available to the compound iterator via the succinct and functional%0A * %7B@link IteratorProvider%7D interface.%0A */%0Apublic class CompoundIterator implements Iterator%0A%7B%0A    /** Used to obtain the set of iterators over which we will iterate. */%0A    public static interface IteratorProvider%0A    %7B%0A        /**%0A         * Returns the next iterator in the set. Should return null when%0A         * we've run out of iterators.%0A         */%0A        public Iterator nextIterator ();%0A    %7D%0A%0A    /**%0A     * Constructs a compound iterator that will iterate over all of the%0A     * iterators provided by the supplied provider, in turn.%0A     */%0A    public CompoundIterator (IteratorProvider provider)%0A    %7B%0A        _provider = provider;%0A        // move to the first iterator%0A        _iter = _provider.nextIterator();%0A    %7D%0A%0A    // documentation inherited%0A    public boolean hasNext ()%0A    %7B%0A        // keep trying iterators until we run out or find an element%0A        while (_iter != null) %7B%0A            try %7B%0A                if (_iter.hasNext()) %7B%0A                    return true;%0A                %7D%0A            %7D catch (NoSuchElementException nsee) %7B%0A                // have to catch this and move to the next iterator%0A                _iter = _provider.nextIterator();%0A            %7D%0A        %7D%0A%0A        return false;%0A    %7D%0A%0A    // documentation inherited%0A    public Object next ()%0A    %7B%0A        // keep trying iterators until we run out or find an element%0A        while (_iter != null) %7B%0A            try %7B%0A                return _iter.next();%0A            %7D catch (NoSuchElementException nsee) %7B%0A                // have to catch this and move to the next iterator%0A                _iter = _provider.nextIterator();%0A            %7D%0A        %7D%0A%0A        throw new NoSuchElementException();%0A    %7D%0A%0A    // documentation inherited%0A    public void remove ()%0A    %7B%0A        if (_iter != null) %7B%0A            _iter.remove();%0A        %7D else %7B%0A            throw new IllegalStateException();%0A        %7D%0A    %7D%0A%0A    /** Our provider of iterators. */%0A    protected IteratorProvider _provider;%0A%0A    /** The iterator currently in use. */%0A    protected Iterator _iter;%0A%7D%0A

Created an iterator that iterates over iterators.