View Javadoc
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    *      https://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  
19  import org.apache.commons.collections4.OrderedMap;
20  import org.apache.commons.collections4.OrderedMapIterator;
21  
22  /**
23   * Provides a base decorator that enables additional functionality to be added
24   * to an OrderedMap via decoration.
25   * <p>
26   * Methods are forwarded directly to the decorated map.
27   * </p>
28   * <p>
29   * This implementation does not perform any special processing with the map views.
30   * Instead it simply returns the set/collection from the wrapped map. This may be
31   * undesirable, for example if you are trying to write a validating implementation
32   * it would provide a loophole around the validation.
33   * But, you might want that loophole, so this class is kept simple.
34   * </p>
35   *
36   * @param <K> The type of the keys in this map
37   * @param <V> The type of the values in this map
38   * @since 3.0
39   */
40  public abstract class AbstractOrderedMapDecorator<K, V> extends AbstractMapDecorator<K, V>
41          implements OrderedMap<K, V> {
42  
43      /**
44       * Constructor only used in deserialization, do not use otherwise.
45       *
46       * @since 3.1
47       */
48      protected AbstractOrderedMapDecorator() {
49      }
50  
51      /**
52       * Constructor that wraps (not copies).
53       *
54       * @param map  The map to decorate, must not be null
55       * @throws NullPointerException if the map is null
56       */
57      public AbstractOrderedMapDecorator(final OrderedMap<K, V> map) {
58          super(map);
59      }
60  
61      /**
62       * Gets the map being decorated.
63       *
64       * @return The decorated map
65       */
66      @Override
67      protected OrderedMap<K, V> decorated() {
68          return (OrderedMap<K, V>) super.decorated();
69      }
70  
71      @Override
72      public K firstKey() {
73          return decorated().firstKey();
74      }
75  
76      @Override
77      public K lastKey() {
78          return decorated().lastKey();
79      }
80  
81      @Override
82      public OrderedMapIterator<K, V> mapIterator() {
83          return decorated().mapIterator();
84      }
85  
86      @Override
87      public K nextKey(final K key) {
88          return decorated().nextKey(key);
89      }
90  
91      @Override
92      public K previousKey(final K key) {
93          return decorated().previousKey(key);
94      }
95  
96  }