    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 java.util.Objects;
    020
    021import org.apache.commons.collections4.OrderedMapIterator;
    022
    023/**
    024 * Provides basic behavior for decorating an ordered map iterator with extra functionality.
    025 * <p>
    026 * All methods are forwarded to the decorated map iterator.
    027 *
    028 * @param <K> the type of keys
    029 * @param <V> the type of mapped values
    030 * @since 3.0
    031 */
    032public class AbstractOrderedMapIteratorDecorator<K, V> implements OrderedMapIterator<K, V> {
    033
    034    /** The iterator being decorated */
    035    private final OrderedMapIterator<K, V> iterator;
    036
    037    /**
    038     * Constructor that decorates the specified iterator.
    039     *
    040     * @param iterator  the iterator to decorate, must not be null
    041     * @throws NullPointerException if the iterator is null
    042     */
    043    public AbstractOrderedMapIteratorDecorator(final OrderedMapIterator<K, V> iterator) {
    044        this.iterator = Objects.requireNonNull(iterator, "iterator");
    045    }
    046
    047    /** {@inheritDoc} */
    048    @Override
    049    public K getKey() {
    050        return iterator.getKey();
    051    }
    052
    053    /**
    054     * Gets the iterator being decorated.
    055     *
    056     * @return the decorated iterator
    057     */
    058    protected OrderedMapIterator<K, V> getOrderedMapIterator() {
    059        return iterator;
    060    }
    061
    062    /** {@inheritDoc} */
    063    @Override
    064    public V getValue() {
    065        return iterator.getValue();
    066    }
    067
    068    /** {@inheritDoc} */
    069    @Override
    070    public boolean hasNext() {
    071        return iterator.hasNext();
    072    }
    073
    074    /** {@inheritDoc} */
    075    @Override
    076    public boolean hasPrevious() {
    077        return iterator.hasPrevious();
    078    }
    079
    080    /** {@inheritDoc} */
    081    @Override
    082    public K next() {
    083        return iterator.next();
    084    }
    085
    086    /** {@inheritDoc} */
    087    @Override
    088    public K previous() {
    089        return iterator.previous();
    090    }
    091
    092    /** {@inheritDoc} */
    093    @Override
    094    public void remove() {
    095        iterator.remove();
    096    }
    097
    098    /** {@inheritDoc} */
    099    @Override
    100    public V setValue(final V obj) {
    101        return iterator.setValue(obj);
    102    }
    103
    104}