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     */
017    package org.apache.commons.collections;
018    
019    /**
020     * Defines a map that maintains order and allows both forward and backward
021     * iteration through that order.
022     * 
023     * @since Commons Collections 3.0
024     * @version $Revision: 646777 $ $Date: 2008-04-10 13:33:15 +0100 (Thu, 10 Apr 2008) $
025     *
026     * @author Stephen Colebourne
027     */
028    public interface OrderedMap extends IterableMap {
029        
030        /**
031         * Obtains an <code>OrderedMapIterator</code> over the map.
032         * <p>
033         * A ordered map iterator is an efficient way of iterating over maps
034         * in both directions.
035         * <pre>
036         * BidiMap map = new TreeBidiMap();
037         * MapIterator it = map.mapIterator();
038         * while (it.hasNext()) {
039         *   Object key = it.next();
040         *   Object value = it.getValue();
041         *   it.setValue("newValue");
042         *   Object previousKey = it.previous();
043         * }
044         * </pre>
045         * 
046         * @return a map iterator
047         */
048        OrderedMapIterator orderedMapIterator();
049        
050        /**
051         * Gets the first key currently in this map.
052         *
053         * @return the first key currently in this map
054         * @throws java.util.NoSuchElementException if this map is empty
055         */
056        public Object firstKey();
057    
058        /**
059         * Gets the last key currently in this map.
060         *
061         * @return the last key currently in this map
062         * @throws java.util.NoSuchElementException if this map is empty
063         */
064        public Object lastKey();
065        
066        /**
067         * Gets the next key after the one specified.
068         *
069         * @param key  the key to search for next from
070         * @return the next key, null if no match or at end
071         */
072        public Object nextKey(Object key);
073    
074        /**
075         * Gets the previous key before the one specified.
076         *
077         * @param key  the key to search for previous from
078         * @return the previous key, null if no match or at start
079         */
080        public Object previousKey(Object key);
081        
082    }