Null-annotated RefDatabase class

No other code changes except adding nullness annotations.

Change-Id: If2606fb208f6690bd4fd7ad953e709a3ebd6398c
Signed-off-by: Andrey Loskutov <loskutov@gmx.de>
This commit is contained in:
Andrey Loskutov 2015-11-25 21:19:05 +01:00
parent 1020f40813
commit 830117e761
1 changed files with 17 additions and 2 deletions

View File

@ -51,6 +51,9 @@
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.annotations.Nullable;
/** /**
* Abstraction of name to {@link ObjectId} mapping. * Abstraction of name to {@link ObjectId} mapping.
* <p> * <p>
@ -132,6 +135,7 @@ public abstract class RefDatabase {
* @since 2.3 * @since 2.3
* @see #isNameConflicting(String) * @see #isNameConflicting(String)
*/ */
@NonNull
public Collection<String> getConflictingNames(String name) public Collection<String> getConflictingNames(String name)
throws IOException { throws IOException {
Map<String, Ref> allRefs = getRefs(ALL); Map<String, Ref> allRefs = getRefs(ALL);
@ -169,6 +173,7 @@ public Collection<String> getConflictingNames(String name)
* @throws IOException * @throws IOException
* the reference space cannot be accessed. * the reference space cannot be accessed.
*/ */
@NonNull
public abstract RefUpdate newUpdate(String name, boolean detach) public abstract RefUpdate newUpdate(String name, boolean detach)
throws IOException; throws IOException;
@ -183,6 +188,7 @@ public abstract RefUpdate newUpdate(String name, boolean detach)
* @throws IOException * @throws IOException
* the reference space cannot be accessed. * the reference space cannot be accessed.
*/ */
@NonNull
public abstract RefRename newRename(String fromName, String toName) public abstract RefRename newRename(String fromName, String toName)
throws IOException; throws IOException;
@ -193,6 +199,7 @@ public abstract RefRename newRename(String fromName, String toName)
* *
* @return a new batch update object. * @return a new batch update object.
*/ */
@NonNull
public BatchRefUpdate newBatchUpdate() { public BatchRefUpdate newBatchUpdate() {
return new BatchRefUpdate(this); return new BatchRefUpdate(this);
} }
@ -223,6 +230,7 @@ public boolean performsAtomicTransactions() {
* @throws IOException * @throws IOException
* the reference space cannot be accessed. * the reference space cannot be accessed.
*/ */
@Nullable
public abstract Ref getRef(String name) throws IOException; public abstract Ref getRef(String name) throws IOException;
/** /**
@ -238,6 +246,7 @@ public boolean performsAtomicTransactions() {
* the reference space cannot be accessed. * the reference space cannot be accessed.
* @since 4.1 * @since 4.1
*/ */
@Nullable
public Ref exactRef(String name) throws IOException { public Ref exactRef(String name) throws IOException {
Ref ref = getRef(name); Ref ref = getRef(name);
if (ref == null || !name.equals(ref.getName())) { if (ref == null || !name.equals(ref.getName())) {
@ -261,6 +270,7 @@ public Ref exactRef(String name) throws IOException {
* the reference space cannot be accessed. * the reference space cannot be accessed.
* @since 4.1 * @since 4.1
*/ */
@NonNull
public Map<String, Ref> exactRef(String... refs) throws IOException { public Map<String, Ref> exactRef(String... refs) throws IOException {
Map<String, Ref> result = new HashMap<>(refs.length); Map<String, Ref> result = new HashMap<>(refs.length);
for (String name : refs) { for (String name : refs) {
@ -285,6 +295,7 @@ public Map<String, Ref> exactRef(String... refs) throws IOException {
* the reference space cannot be accessed. * the reference space cannot be accessed.
* @since 4.1 * @since 4.1
*/ */
@Nullable
public Ref firstExactRef(String... refs) throws IOException { public Ref firstExactRef(String... refs) throws IOException {
for (String name : refs) { for (String name : refs) {
Ref ref = exactRef(name); Ref ref = exactRef(name);
@ -308,6 +319,7 @@ public Ref firstExactRef(String... refs) throws IOException {
* @throws IOException * @throws IOException
* the reference space cannot be accessed. * the reference space cannot be accessed.
*/ */
@NonNull
public abstract Map<String, Ref> getRefs(String prefix) throws IOException; public abstract Map<String, Ref> getRefs(String prefix) throws IOException;
/** /**
@ -322,6 +334,7 @@ public Ref firstExactRef(String... refs) throws IOException {
* @throws IOException * @throws IOException
* the reference space cannot be accessed. * the reference space cannot be accessed.
*/ */
@NonNull
public abstract List<Ref> getAdditionalRefs() throws IOException; public abstract List<Ref> getAdditionalRefs() throws IOException;
/** /**
@ -338,10 +351,11 @@ public Ref firstExactRef(String... refs) throws IOException {
* @return {@code ref} if {@code ref.isPeeled()} is true; otherwise a new * @return {@code ref} if {@code ref.isPeeled()} is true; otherwise a new
* Ref object representing the same data as Ref, but isPeeled() will * Ref object representing the same data as Ref, but isPeeled() will
* be true and getPeeledObjectId() will contain the peeled object * be true and getPeeledObjectId() will contain the peeled object
* (or null). * (or {@code null}).
* @throws IOException * @throws IOException
* the reference space or object space cannot be accessed. * the reference space or object space cannot be accessed.
*/ */
@NonNull
public abstract Ref peel(Ref ref) throws IOException; public abstract Ref peel(Ref ref) throws IOException;
/** /**
@ -365,9 +379,10 @@ public void refresh() {
* @param name * @param name
* short name of ref to find, e.g. "master" to find * short name of ref to find, e.g. "master" to find
* "refs/heads/master" in map. * "refs/heads/master" in map.
* @return The first ref matching the name, or null if not found. * @return The first ref matching the name, or {@code null} if not found.
* @since 3.4 * @since 3.4
*/ */
@Nullable
public static Ref findRef(Map<String, Ref> map, String name) { public static Ref findRef(Map<String, Ref> map, String name) {
for (String prefix : SEARCH_PATH) { for (String prefix : SEARCH_PATH) {
String fullname = prefix + name; String fullname = prefix + name;