1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 * 19 */ 20 package org.apache.directory.mavibot.btree; 21 22 23 import java.io.IOException; 24 25 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException; 26 27 28 /** 29 * A Cursor is used to fetch elements in a BTree and is returned by the 30 * @see BTree#browse method. The cursor <strng>must</strong> be closed 31 * when the user is done with it. 32 * <p> 33 * 34 * @param <K> The type for the Key 35 * 36 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 37 */ 38 public interface Cursor<K> 39 { 40 /** Static value for the beforeFrst and afterLast positions */ 41 int BEFORE_FIRST = -1; 42 int AFTER_LAST = -2; 43 44 45 /** 46 * Tells if the cursor can return a next element 47 * @return true if there are some more elements 48 * @throws IOException 49 * @throws EndOfFileExceededException 50 */ 51 boolean hasNext() throws EndOfFileExceededException, IOException; 52 53 54 /** 55 * Tells if the cursor can return a previous element 56 * @return true if there are some more elements 57 * @throws IOException 58 * @throws EndOfFileExceededException 59 */ 60 boolean hasPrev() throws EndOfFileExceededException, IOException; 61 62 63 /** 64 * Closes the cursor, thus releases the associated transaction 65 */ 66 void close(); 67 68 69 /** 70 * moves the cursor to the same position that was given at the time of instantiating the cursor. 71 * 72 * For example, if the cursor was created using browse() method, then beforeFirst() will 73 * place the cursor before the 0th position. 74 * 75 * If the cursor was created using browseFrom(K), then calling beforeFirst() will reset the position 76 * to the just before the position where K is present. 77 */ 78 void beforeFirst() throws IOException; 79 80 81 /** 82 * Places the cursor at the end of the last position 83 * 84 * @throws IOException 85 */ 86 void afterLast() throws IOException; 87 }