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.collections.map;
18  
19  import org.apache.commons.collections.OrderedMap;
20  import org.apache.commons.collections.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   * This implementation does not perform any special processing with the map views.
29   * Instead it simply returns the set/collection from the wrapped map. This may be
30   * undesirable, for example if you are trying to write a validating implementation
31   * it would provide a loophole around the validation.
32   * But, you might want that loophole, so this class is kept simple.
33   *
34   * @since 3.0
35   * @version $Id: AbstractOrderedMapDecorator.java 1429905 2013-01-07 17:15:14Z ggregory $
36   */
37  public abstract class AbstractOrderedMapDecorator<K, V> extends AbstractMapDecorator<K, V>
38          implements OrderedMap<K, V> {
39  
40      /**
41       * Constructor only used in deserialization, do not use otherwise.
42       * @since 3.1
43       */
44      protected AbstractOrderedMapDecorator() {
45          super();
46      }
47  
48      /**
49       * Constructor that wraps (not copies).
50       *
51       * @param map  the map to decorate, must not be null
52       * @throws IllegalArgumentException if the collection is null
53       */
54      public AbstractOrderedMapDecorator(final OrderedMap<K, V> map) {
55          super(map);
56      }
57  
58      /**
59       * Gets the map being decorated.
60       * 
61       * @return the decorated map
62       */
63      @Override
64      protected OrderedMap<K, V> decorated() {
65          return (OrderedMap<K, V>) super.decorated();
66      }
67  
68      //-----------------------------------------------------------------------
69      public K firstKey() {
70          return decorated().firstKey();
71      }
72  
73      public K lastKey() {
74          return decorated().lastKey();
75      }
76  
77      public K nextKey(final K key) {
78          return decorated().nextKey(key);
79      }
80  
81      public K previousKey(final K key) {
82          return decorated().previousKey(key);
83      }
84  
85      @Override
86      public OrderedMapIterator<K, V> mapIterator() {
87          return decorated().mapIterator();
88      }
89  
90  }