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.map;
018
019import org.apache.commons.collections4.OrderedMap;
020import org.apache.commons.collections4.OrderedMapIterator;
021
022/**
023 * Provides a base decorator that enables additional functionality to be added
024 * to an OrderedMap via decoration.
025 * <p>
026 * Methods are forwarded directly to the decorated map.
027 * <p>
028 * This implementation does not perform any special processing with the map views.
029 * Instead it simply returns the set/collection from the wrapped map. This may be
030 * undesirable, for example if you are trying to write a validating implementation
031 * it would provide a loophole around the validation.
032 * But, you might want that loophole, so this class is kept simple.
033 *
034 * @param <K> the type of the keys in this map
035 * @param <V> the type of the values in this map
036 * @since 3.0
037 */
038public abstract class AbstractOrderedMapDecorator<K, V> extends AbstractMapDecorator<K, V>
039        implements OrderedMap<K, V> {
040
041    /**
042     * Constructor only used in deserialization, do not use otherwise.
043     * @since 3.1
044     */
045    protected AbstractOrderedMapDecorator() {
046        super();
047    }
048
049    /**
050     * Constructor that wraps (not copies).
051     *
052     * @param map  the map to decorate, must not be null
053     * @throws NullPointerException if the map is null
054     */
055    public AbstractOrderedMapDecorator(final OrderedMap<K, V> map) {
056        super(map);
057    }
058
059    /**
060     * Gets the map being decorated.
061     *
062     * @return the decorated map
063     */
064    @Override
065    protected OrderedMap<K, V> decorated() {
066        return (OrderedMap<K, V>) super.decorated();
067    }
068
069    //-----------------------------------------------------------------------
070    @Override
071    public K firstKey() {
072        return decorated().firstKey();
073    }
074
075    @Override
076    public K lastKey() {
077        return decorated().lastKey();
078    }
079
080    @Override
081    public K nextKey(final K key) {
082        return decorated().nextKey(key);
083    }
084
085    @Override
086    public K previousKey(final K key) {
087        return decorated().previousKey(key);
088    }
089
090    @Override
091    public OrderedMapIterator<K, V> mapIterator() {
092        return decorated().mapIterator();
093    }
094
095}