    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      https://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017
    018package org.apache.commons.collections4;
    019
    020/**
    021 * Defines a map that maintains order and allows both forward and backward iteration through that order.
    022 *
    023 * @param <K> The type of the keys in the map.
    024 * @param <V> The type of the values in the map.
    025 * @since 3.0
    026 */
    027public interface OrderedMap<K, V> extends IterableMap<K, V> {
    028
    029    /**
    030     * Gets the first key currently in this map.
    031     *
    032     * @return The first key currently in this map.
    033     * @throws java.util.NoSuchElementException if this map is empty.
    034     */
    035    K firstKey();
    036
    037    /**
    038     * Gets the last key currently in this map.
    039     *
    040     * @return The last key currently in this map.
    041     * @throws java.util.NoSuchElementException if this map is empty.
    042     */
    043    K lastKey();
    044
    045    /**
    046     * Obtains an {@code OrderedMapIterator} over the map.
    047     * <p>
    048     * An ordered map iterator is an efficient way of iterating over maps in both directions.
    049     * </p>
    050     *
    051     * @return A map iterator.
    052     */
    053    @Override
    054    OrderedMapIterator<K, V> mapIterator();
    055
    056    /**
    057     * Gets the next key after the one specified.
    058     *
    059     * @param key The key to search for next from.
    060     * @return The next key, null if no match or at end.
    061     */
    062    K nextKey(K key);
    063
    064    /**
    065     * Gets the previous key before the one specified.
    066     *
    067     * @param key The key to search for previous from.
    068     * @return The previous key, null if no match or at start.
    069     */
    070    K previousKey(K key);
    071}