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