View Javadoc
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  
11  package org.eclipse.jgit.internal.storage.reftable;
12  
13  import java.io.IOException;
14  
15  import org.eclipse.jgit.lib.Ref;
16  
17  /**
18   * Iterator over references inside a
19   * {@link org.eclipse.jgit.internal.storage.reftable.Reftable}.
20   */
21  public abstract class RefCursor implements AutoCloseable {
22  	/**
23  	 * Check if another reference is available.
24  	 *
25  	 * @return {@code true} if there is another result.
26  	 * @throws java.io.IOException
27  	 *             references cannot be read.
28  	 */
29  	public abstract boolean next() throws IOException;
30  
31  	/**
32  	 * Seeks forward to the first ref record lexicographically beyond
33  	 * {@code prefixName} that doesn't start with {@code prefixName}. If there are
34  	 * no more results, skipping some refs won't add new results. E.g if we create a
35  	 * RefCursor that returns only results with a specific prefix, skipping that
36  	 * prefix won't give results that are not part of the original prefix.
37  	 *
38  	 * @param prefixName prefix that should be skipped. All previous refs before it
39  	 *                   will be skipped.
40  	 * @throws java.io.IOException references cannot be read.
41  	 */
42  	public abstract void seekPastPrefix(String prefixName) throws IOException;
43  
44  	/**
45  	 * Get reference at the current position.
46  	 *
47  	 * @return reference at the current position.
48  	 */
49  	public abstract Ref getRef();
50  
51  	/**
52  	 * Whether the current reference was deleted.
53  	 *
54  	 * @return {@code true} if the current reference was deleted.
55  	 */
56  	public boolean wasDeleted() {
57  		Ref r = getRef();
58  		return r.getStorage() == Ref.Storage.NEW && r.getObjectId() == null;
59  	}
60  
61  	/** {@inheritDoc} */
62  	@Override
63  	public abstract void close();
64  }