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 org.forgerock.opendj.ldap.ByteSequence;
029
030/**
031 * Sequential cursor extended with navigation methods.
032 * @param <K> Type of the record's key
033 * @param <V> Type of the record's value
034 */
035public interface Cursor<K,V> extends SequentialCursor<K, V>
036{
037  /**
038   * Positions the cursor to the provided key if it exists in the tree.
039   *
040   * @param key
041   *          the key where to position the cursor
042   * @return {@code true} if the cursor could be positioned to the key,
043   *         {@code false} otherwise
044   */
045  boolean positionToKey(ByteSequence key);
046
047  /**
048   * Positions the cursor to the provided key if it exists in the tree,
049   * or else the lesser key greater than the provided key in the tree.
050   *
051   * @param key
052   *          the key where to position the cursor
053   * @return {@code true} if the cursor could be positioned to the key
054   *         or the next one, {@code false} otherwise
055   */
056  boolean positionToKeyOrNext(ByteSequence key);
057
058  /**
059   * Positions the cursor to the last key in the tree.
060   *
061   * @return {@code true} if the cursor could be positioned to the last key,
062   *         {@code false} otherwise
063   */
064  boolean positionToLastKey();
065
066  /**
067   * Positions the cursor to the specified index within the tree. Implementations may take advantage
068   * of optimizations provided by the underlying storage, such as counted B-Trees.
069   *
070   * @param index
071   *          the index where the cursor should be positioned, (0 is the first record).
072   * @return {@code true} if the cursor could be positioned to the index, {@code false} otherwise
073   */
074  boolean positionToIndex(int index);
075}