RefCursor.java

  1. /*
  2.  * Copyright (C) 2017, Google Inc. and others
  3.  *
  4.  * This program and the accompanying materials are made available under the
  5.  * terms of the Eclipse Distribution License v. 1.0 which is available at
  6.  * https://www.eclipse.org/org/documents/edl-v10.php.
  7.  *
  8.  * SPDX-License-Identifier: BSD-3-Clause
  9.  */

  10. package org.eclipse.jgit.internal.storage.reftable;

  11. import java.io.IOException;

  12. import org.eclipse.jgit.lib.Ref;

  13. /**
  14.  * Iterator over references inside a
  15.  * {@link org.eclipse.jgit.internal.storage.reftable.Reftable}.
  16.  */
  17. public abstract class RefCursor implements AutoCloseable {
  18.     /**
  19.      * Check if another reference is available.
  20.      *
  21.      * @return {@code true} if there is another result.
  22.      * @throws java.io.IOException
  23.      *             references cannot be read.
  24.      */
  25.     public abstract boolean next() throws IOException;

  26.     /**
  27.      * Seeks forward to the first ref record lexicographically beyond
  28.      * {@code prefixName} that doesn't start with {@code prefixName}. If there are
  29.      * no more results, skipping some refs won't add new results. E.g if we create a
  30.      * RefCursor that returns only results with a specific prefix, skipping that
  31.      * prefix won't give results that are not part of the original prefix.
  32.      *
  33.      * @param prefixName prefix that should be skipped. All previous refs before it
  34.      *                   will be skipped.
  35.      * @throws java.io.IOException references cannot be read.
  36.      */
  37.     public abstract void seekPastPrefix(String prefixName) throws IOException;

  38.     /**
  39.      * Get reference at the current position.
  40.      *
  41.      * @return reference at the current position.
  42.      */
  43.     public abstract Ref getRef();

  44.     /**
  45.      * Whether the current reference was deleted.
  46.      *
  47.      * @return {@code true} if the current reference was deleted.
  48.      */
  49.     public boolean wasDeleted() {
  50.         Ref r = getRef();
  51.         return r.getStorage() == Ref.Storage.NEW && r.getObjectId() == null;
  52.     }

  53.     /** {@inheritDoc} */
  54.     @Override
  55.     public abstract void close();
  56. }