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