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 */
017package org.apache.commons.collections4.iterators;
018
019import org.apache.commons.collections4.MapIterator;
020
021/**
022 * Provides basic behaviour for decorating a map iterator with extra functionality.
023 * <p>
024 * All methods are forwarded to the decorated map iterator.
025 *
026 * @since 3.0
027 * @version $Id: AbstractMapIteratorDecorator.html 972421 2015-11-14 20:00:04Z tn $
028 */
029public class AbstractMapIteratorDecorator<K, V> implements MapIterator<K, V> {
030
031    /** The iterator being decorated */
032    private final MapIterator<K, V> iterator;
033
034    //-----------------------------------------------------------------------
035    /**
036     * Constructor that decorates the specified iterator.
037     *
038     * @param iterator  the iterator to decorate, must not be null
039     * @throws IllegalArgumentException if the collection is null
040     */
041    public AbstractMapIteratorDecorator(final MapIterator<K, V> iterator) {
042        super();
043        if (iterator == null) {
044            throw new IllegalArgumentException("MapIterator must not be null");
045        }
046        this.iterator = iterator;
047    }
048
049    /**
050     * Gets the iterator being decorated.
051     *
052     * @return the decorated iterator
053     */
054    protected MapIterator<K, V> getMapIterator() {
055        return iterator;
056    }
057
058    //-----------------------------------------------------------------------
059
060    /** {@inheritDoc} */
061    public boolean hasNext() {
062        return iterator.hasNext();
063    }
064
065    /** {@inheritDoc} */
066    public K next() {
067        return iterator.next();
068    }
069
070    /** {@inheritDoc} */
071    public void remove() {
072        iterator.remove();
073    }
074
075    /** {@inheritDoc} */
076    public K getKey() {
077        return iterator.getKey();
078    }
079
080    /** {@inheritDoc} */
081    public V getValue() {
082        return iterator.getValue();
083    }
084
085    /** {@inheritDoc} */
086    public V setValue(final V obj) {
087        return iterator.setValue(obj);
088    }
089
090}