001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.commons.collections.iterators;
018    
019    import java.util.Iterator;
020    
021    /** 
022     * Provides basic behaviour for decorating an iterator with extra functionality.
023     * <p>
024     * All methods are forwarded to the decorated iterator.
025     *
026     * @since Commons Collections 3.0
027     * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
028     * 
029     * @author James Strachan
030     * @author Stephen Colebourne
031     */
032    public class AbstractIteratorDecorator implements Iterator {
033    
034        /** The iterator being decorated */
035        protected final Iterator iterator;
036    
037        //-----------------------------------------------------------------------
038        /**
039         * Constructor that decorates the specified iterator.
040         *
041         * @param iterator  the iterator to decorate, must not be null
042         * @throws IllegalArgumentException if the collection is null
043         */
044        public AbstractIteratorDecorator(Iterator iterator) {
045            super();
046            if (iterator == null) {
047                throw new IllegalArgumentException("Iterator must not be null");
048            }
049            this.iterator = iterator;
050        }
051    
052        /**
053         * Gets the iterator being decorated.
054         * 
055         * @return the decorated iterator
056         */
057        protected Iterator getIterator() {
058            return iterator;
059        }
060    
061        //-----------------------------------------------------------------------
062        public boolean hasNext() {
063            return iterator.hasNext();
064        }
065    
066        public Object next() {
067            return iterator.next();
068        }
069    
070        public void remove() {
071            iterator.remove();
072        }
073    
074    }