001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2014-2015 ForgeRock AS. 015 */ 016package org.opends.server.backends.pluggable.spi; 017 018import java.io.Closeable; 019import java.util.NoSuchElementException; 020 021/** 022 * Cursor extended with navigation methods. 023 * @param <K> Type of the record's key 024 * @param <V> Type of the record's value 025 */ 026public interface SequentialCursor<K,V> extends Closeable 027{ 028 /** 029 * Moves this cursor to the next record in the tree. 030 * 031 * @return {@code true} if the cursor has moved to the next record, 032 * {@code false} if no next record exists leaving cursor 033 * in undefined state. 034 */ 035 boolean next(); 036 037 /** 038 * Check whether this cursor is currently pointing to valid record. 039 * 040 * @return {@code true} if the cursor is pointing to a valid entry, 041 * {@code false} if cursor is not pointing to a valid entry 042 */ 043 boolean isDefined(); 044 045 /** 046 * Returns the key of the record on which this cursor is currently positioned. 047 * 048 * @return the current record's key. 049 * @throws NoSuchElementException if the cursor is not defined. 050 */ 051 K getKey() throws NoSuchElementException; 052 053 /** 054 * Returns the value of the record on which this cursor is currently positioned. 055 * 056 * @return the current record's value. 057 * @throws NoSuchElementException if the cursor is not defined. 058 */ 059 V getValue() throws NoSuchElementException; 060 061 /** 062 * Deletes the record on which this cursor is currently positioned. This method does not alter the position of the 063 * cursor. In particular, {@link #next()} must be called in order to point to the next record. The behavior of 064 * methods {@link #getKey()} and {@link #getValue()} after this method returns is undefined. 065 * 066 * @throws NoSuchElementException if the cursor is not defined. 067 * @throws UnsupportedOperationException if the cursor implementation does not support updates. 068 */ 069 void delete() throws NoSuchElementException, UnsupportedOperationException; 070 071 /** {@inheritDoc} */ 072 @Override 073 void close(); 074}