    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 *      http://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 */
    017package org.apache.commons.collections4;
    018
    019/**
    020 * Defines a map that maintains order and allows both forward and backward
    021 * 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 *
    026 * @since 3.0
    027 */
    028public interface OrderedMap<K, V> extends IterableMap<K, V> {
    029
    030    /**
    031     * Gets the first key currently in this map.
    032     *
    033     * @return the first key currently in this map
    034     * @throws java.util.NoSuchElementException if this map is empty
    035     */
    036    K firstKey();
    037
    038    /**
    039     * Gets the last key currently in this map.
    040     *
    041     * @return the last key currently in this map
    042     * @throws java.util.NoSuchElementException if this map is empty
    043     */
    044    K lastKey();
    045
    046    /**
    047     * Obtains an {@code OrderedMapIterator} over the map.
    048     * <p>
    049     * An ordered map iterator is an efficient way of iterating over maps
    050     * in both directions.
    051     *
    052     * @return a map iterator
    053     */
    054    @Override
    055    OrderedMapIterator<K, V> mapIterator();
    056
    057    /**
    058     * Gets the next key after the one specified.
    059     *
    060     * @param key  the key to search for next from
    061     * @return the next key, null if no match or at end
    062     */
    063    K nextKey(K key);
    064
    065    /**
    066     * Gets the previous key before the one specified.
    067     *
    068     * @param key  the key to search for previous from
    069     * @return the previous key, null if no match or at start
    070     */
    071    K previousKey(K key);
    072
    073}