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.fusesource.hawtdb.api;
018    
019    import java.io.IOException;
020    import java.util.Iterator;
021    import java.util.Map;
022    
023    /**
024     * Provides Key/Value storage and retrieval.
025     *
026     * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
027     */
028    public interface SortedIndex<Key,Value> extends Index<Key,Value>, Iterable<Map.Entry<Key, Value>> {
029    
030        /**
031         * @return
032         * @throws IOException
033         */
034        public Iterator<Map.Entry<Key,Value>> iterator();
035    
036        /**
037         * @return
038         * @throws IOException
039         */
040        public Iterator<Map.Entry<Key,Value>> iterator(Predicate<Key> predicate);
041    
042        /**
043         * 
044         * @param initialKey
045         * @return
046         */
047        public Iterator<Map.Entry<Key, Value>> iterator(Key initialKey);
048    
049    
050        /**
051         * Traverses the visitor over the stored entries in this index.  The visitor can control
052         * which keys and values are visited.
053         *
054         * @param visitor
055         */
056        public void visit(IndexVisitor<Key, Value> visitor);
057    
058        /**
059         *
060         * @return the first key/value pair in the index or null if empty.
061         */
062        public Map.Entry<Key, Value> getFirst();
063    
064        /**
065         * @return the last key/value pair in the index or null if empty.
066         */
067        public Map.Entry<Key, Value> getLast();
068    
069    
070    }