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    *      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.bidimap;
18  
19  import org.apache.commons.collections4.OrderedBidiMap;
20  import org.apache.commons.collections4.OrderedMapIterator;
21  
22  /**
23   * Provides a base decorator that enables additional functionality to be added
24   * to an OrderedBidiMap 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 inverse 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 AbstractOrderedBidiMapDecorator<K, V>
41          extends AbstractBidiMapDecorator<K, V>
42          implements OrderedBidiMap<K, V> {
43  
44      /**
45       * Constructor that wraps (not copies).
46       *
47       * @param map  the map to decorate, must not be null
48       * @throws NullPointerException if the collection is null
49       */
50      protected AbstractOrderedBidiMapDecorator(final OrderedBidiMap<K, V> map) {
51          super(map);
52      }
53  
54      /**
55       * Gets the map being decorated.
56       *
57       * @return the decorated map
58       */
59      @Override
60      protected OrderedBidiMap<K, V> decorated() {
61          return (OrderedBidiMap<K, V>) super.decorated();
62      }
63  
64      @Override
65      public K firstKey() {
66          return decorated().firstKey();
67      }
68  
69      @Override
70      public OrderedBidiMap<V, K> inverseBidiMap() {
71          return decorated().inverseBidiMap();
72      }
73  
74      @Override
75      public K lastKey() {
76          return decorated().lastKey();
77      }
78  
79      @Override
80      public OrderedMapIterator<K, V> mapIterator() {
81          return decorated().mapIterator();
82      }
83  
84      @Override
85      public K nextKey(final K key) {
86          return decorated().nextKey(key);
87      }
88  
89      @Override
90      public K previousKey(final K key) {
91          return decorated().previousKey(key);
92      }
93  
94  }