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 * @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 49 * in both directions. 50 * </p> 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 }