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.util.Comparator;
020    import java.util.List;
021    
022    /**
023     * A predicate is used to narrow down the keys that an application is interested in 
024     * accessing.
025     *
026     * You can implement custom predicate implementations by implementing the Predicate interface or
027     * you can you some of the predefined predicate classes.
028     * 
029     * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
030     * @param <Key>
031     */
032    public interface Predicate<Key> {
033        
034        /**
035         * 
036         * @param first the first key in the range or null if unknown
037         * @param second the last key in the range or null if unknown
038         * @param comparator the Comparator configured for the index, may be null.
039         *
040         * @return true if the predicate is interested in keys in the range.
041         */
042        boolean isInterestedInKeysBetween(Key first, Key second, Comparator comparator);
043        
044        /**
045         * @param key
046         * @param comparator the Comparator configured for the index, may be null.
047         *
048         * @return true if the predicate is interested in the key
049         */
050        boolean isInterestedInKey(Key key, Comparator comparator);
051        
052    }