AbstractOrderedMapDecorator.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.apache.commons.collections4.map;

  18. import org.apache.commons.collections4.OrderedMap;
  19. import org.apache.commons.collections4.OrderedMapIterator;

  20. /**
  21.  * Provides a base decorator that enables additional functionality to be added
  22.  * to an OrderedMap via decoration.
  23.  * <p>
  24.  * Methods are forwarded directly to the decorated map.
  25.  * </p>
  26.  * <p>
  27.  * This implementation does not perform any special processing with the map views.
  28.  * Instead it simply returns the set/collection from the wrapped map. This may be
  29.  * undesirable, for example if you are trying to write a validating implementation
  30.  * it would provide a loophole around the validation.
  31.  * But, you might want that loophole, so this class is kept simple.
  32.  * </p>
  33.  *
  34.  * @param <K> the type of the keys in this map
  35.  * @param <V> the type of the values in this map
  36.  * @since 3.0
  37.  */
  38. public abstract class AbstractOrderedMapDecorator<K, V> extends AbstractMapDecorator<K, V>
  39.         implements OrderedMap<K, V> {

  40.     /**
  41.      * Constructor only used in deserialization, do not use otherwise.
  42.      * @since 3.1
  43.      */
  44.     protected AbstractOrderedMapDecorator() {
  45.     }

  46.     /**
  47.      * Constructor that wraps (not copies).
  48.      *
  49.      * @param map  the map to decorate, must not be null
  50.      * @throws NullPointerException if the map is null
  51.      */
  52.     public AbstractOrderedMapDecorator(final OrderedMap<K, V> map) {
  53.         super(map);
  54.     }

  55.     /**
  56.      * Gets the map being decorated.
  57.      *
  58.      * @return the decorated map
  59.      */
  60.     @Override
  61.     protected OrderedMap<K, V> decorated() {
  62.         return (OrderedMap<K, V>) super.decorated();
  63.     }

  64.     @Override
  65.     public K firstKey() {
  66.         return decorated().firstKey();
  67.     }

  68.     @Override
  69.     public K lastKey() {
  70.         return decorated().lastKey();
  71.     }

  72.     @Override
  73.     public OrderedMapIterator<K, V> mapIterator() {
  74.         return decorated().mapIterator();
  75.     }

  76.     @Override
  77.     public K nextKey(final K key) {
  78.         return decorated().nextKey(key);
  79.     }

  80.     @Override
  81.     public K previousKey(final K key) {
  82.         return decorated().previousKey(key);
  83.     }

  84. }