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;
18  
19  /**
20   * Defines a map that maintains order and allows both forward and backward
21   * iteration through that order.
22   *
23   * @param <K> the type of the keys in the map
24   * @param <V> the type of the values in the map
25   *
26   * @since 3.0
27   */
28  public interface OrderedMap<K, V> extends IterableMap<K, V> {
29  
30      /**
31       * Gets the first key currently in this map.
32       *
33       * @return the first key currently in this map
34       * @throws java.util.NoSuchElementException if this map is empty
35       */
36      K firstKey();
37  
38      /**
39       * Gets the last key currently in this map.
40       *
41       * @return the last key currently in this map
42       * @throws java.util.NoSuchElementException if this map is empty
43       */
44      K lastKey();
45  
46      /**
47       * Obtains an {@code OrderedMapIterator} over the map.
48       * <p>
49       * An ordered map iterator is an efficient way of iterating over maps
50       * in both directions.
51       *
52       * @return a map iterator
53       */
54      @Override
55      OrderedMapIterator<K, V> mapIterator();
56  
57      /**
58       * Gets the next key after the one specified.
59       *
60       * @param key  the key to search for next from
61       * @return the next key, null if no match or at end
62       */
63      K nextKey(K key);
64  
65      /**
66       * Gets the previous key before the one specified.
67       *
68       * @param key  the key to search for previous from
69       * @return the previous key, null if no match or at start
70       */
71      K previousKey(K key);
72  
73  }