public static Builder<ByteBuffer> create() {
  return new Builder<>(PROXY_OPTIMAL);
} public static <T> KeyRange<T> all() {
  return (KeyRange<T>) FW;
} public static <T> KeyRange<T> allBackward() {
  return (KeyRange<T>) BK;
} public static <T> KeyRange<T> atLeast(final T start) {
  return new KeyRange<>(KeyRangeType.FORWARD_AT_LEAST, start, null);
} public static <T> KeyRange<T> atLeastBackward(final T start) {
  return new KeyRange<>(KeyRangeType.BACKWARD_AT_LEAST, start, null);
} public static <T> KeyRange<T> atMost(final T stop) {
  return new KeyRange<>(KeyRangeType.FORWARD_AT_MOST, null, stop);
} public static <T> KeyRange<T> atMostBackward(final T stop) {
  return new KeyRange<>(KeyRangeType.BACKWARD_AT_MOST, null, stop);
} public static <T> KeyRange<T> closed(final T start, final T stop) {
  return new KeyRange<>(KeyRangeType.FORWARD_CLOSED, start, stop);
} public static <T> KeyRange<T> closedBackward(final T start, final T stop) {
  return new KeyRange<>(KeyRangeType.BACKWARD_CLOSED, start, stop);
} public static <T> KeyRange<T> closedOpen(final T start, final T stop) {
  return new KeyRange<>(KeyRangeType.FORWARD_CLOSED_OPEN, start, stop);
} public static <T> KeyRange<T> closedOpenBackward(final T start, final T stop) {
  return new KeyRange<>(KeyRangeType.BACKWARD_CLOSED_OPEN, start, stop);
} public static <T> KeyRange<T> greaterThan(final T start) {
  return new KeyRange<>(KeyRangeType.FORWARD_GREATER_THAN, start, null);
} public static <T> KeyRange<T> greaterThanBackward(final T start) {
  return new KeyRange<>(KeyRangeType.BACKWARD_GREATER_THAN, start, null);
} public static <T> KeyRange<T> lessThan(final T stop) {
  return new KeyRange<>(KeyRangeType.FORWARD_LESS_THAN, null, stop);
} public static <T> KeyRange<T> lessThanBackward(final T stop) {
  return new KeyRange<>(KeyRangeType.BACKWARD_LESS_THAN, null, stop);
} public static <T> KeyRange<T> open(final T start, final T stop) {
  return new KeyRange<>(KeyRangeType.FORWARD_OPEN, start, stop);
} public static <T> KeyRange<T> openBackward(final T start, final T stop) {
  return new KeyRange<>(KeyRangeType.BACKWARD_OPEN, start, stop);
} public static <T> KeyRange<T> openClosed(final T start, final T stop) {
  return new KeyRange<>(KeyRangeType.FORWARD_OPEN_CLOSED, start, stop);
} public static <T> KeyRange<T> openClosedBackward(final T start, final T stop) {
  return new KeyRange<>(KeyRangeType.BACKWARD_OPEN_CLOSED, start, stop);
} public static final String DB_1 = "test-db-1"; @SuppressWarnings("PMD.AvoidUsingOctalValues")
public static final int POSIX_MODE = 0664; static ByteBuffer bb(final int value) {
  final ByteBuffer bb = allocateDirect(BYTES);
  bb.putInt(value).flip();
  return bb;
} public static final class KeyVal<T> {

  private T k;
  private T v;

  /**
   * The key.
   *
   * @return key
   */
  public T key() {
    return k;
  }

  /**
   * The value.
   *
   * @return value
   */
  public T val() {
    return v;
  }

  void setK(final T key) {
    this.k = key;
  }

  void setV(final T val) {
    this.v = val;
  }

}
import static com.jakewharton.byteunits.BinaryByteUnit.KIBIBYTES;
import static java.util.Arrays.asList;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.lmdbjava.DbiFlags.MDB_CREATE;
import static org.lmdbjava.Env.create;
import static org.lmdbjava.EnvFlags.MDB_NOSUBDIR;
import static org.lmdbjava.KeyRange.all;
import static org.lmdbjava.KeyRange.allBackward;
import static org.lmdbjava.KeyRange.atLeast;
import static org.lmdbjava.KeyRange.atLeastBackward;
import static org.lmdbjava.KeyRange.atMost;
import static org.lmdbjava.KeyRange.atMostBackward;
import static org.lmdbjava.KeyRange.closed;
import static org.lmdbjava.KeyRange.closedBackward;
import static org.lmdbjava.KeyRange.closedOpen;
import static org.lmdbjava.KeyRange.closedOpenBackward;
import static org.lmdbjava.KeyRange.greaterThan;
import static org.lmdbjava.KeyRange.greaterThanBackward;
import static org.lmdbjava.KeyRange.lessThan;
import static org.lmdbjava.KeyRange.lessThanBackward;
import static org.lmdbjava.KeyRange.open;
import static org.lmdbjava.KeyRange.openBackward;
import static org.lmdbjava.KeyRange.openClosed;
import static org.lmdbjava.KeyRange.openClosedBackward;
import static org.lmdbjava.PutFlags.MDB_NOOVERWRITE;
import static org.lmdbjava.TestUtils.DB_1;
import static org.lmdbjava.TestUtils.POSIX_MODE;
import static org.lmdbjava.TestUtils.bb;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Deque;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import com.google.common.primitives.UnsignedBytes;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.lmdbjava.CursorIterable.KeyVal;
/*-
 * #%L
 * LmdbJava
 * %%
 * Copyright (C) 2016 - 2021 The LmdbJava Open Source Project
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

package org.lmdbjava;




/**
 * Test {@link CursorIterable}.
 */
public final class CursorIterableTest {

  @Rule
  public final TemporaryFolder tmp = new TemporaryFolder();
  private Dbi<ByteBuffer> db;
  private Env<ByteBuffer> env;
  private Deque<Integer> list;

  @After
  public void after() {
    env.close();
  }

  @Test
  public void allBackwardTest() {
    verify(allBackward(), 8, 6, 4, 2);
  }

  @Test
  public void allTest() {
    verify(all(), 2, 4, 6, 8);
  }

  @Test
  public void atLeastBackwardTest() {
    verify(atLeastBackward(bb(5)), 4, 2);