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 static final int BEFORE_FIRST = -1; 42 static final int AFTER_LAST = -2; 43 44 /** 45 * Tells if the cursor can return a next element 46 * @return true if there are some more elements 47 * @throws IOException 48 * @throws EndOfFileExceededException 49 */ 50 boolean hasNext() throws EndOfFileExceededException, IOException; 51 52 53 /** 54 * Tells if the cursor can return a previous element 55 * @return true if there are some more elements 56 * @throws IOException 57 * @throws EndOfFileExceededException 58 */ 59 boolean hasPrev() throws EndOfFileExceededException, IOException; 60 61 62 /** 63 * Closes the cursor, thus releases the associated transaction 64 */ 65 void close(); 66 67 68 /** 69 * moves the cursor to the same position that was given at the time of instantiating the cursor. 70 * 71 * For example, if the cursor was created using browse() method, then beforeFirst() will 72 * place the cursor before the 0th position. 73 * 74 * If the cursor was created using browseFrom(K), then calling beforeFirst() will reset the position 75 * to the just before the position where K is present. 76 */ 77 void beforeFirst() throws IOException; 78 79 80 /** 81 * Places the cursor at the end of the last position 82 * 83 * @throws IOException 84 */ 85 public void afterLast() throws IOException; 86 }