Reduce method count for GitDBBranch

This commit is contained in:
Paul Campbell 2018-06-15 19:20:34 +01:00
parent 58daa2a6a6
commit 9b8c4765ae
5 changed files with 12 additions and 23 deletions

View file

@ -93,7 +93,7 @@ public interface GitDBBranch {
* *
* @return the branch name * @return the branch name
*/ */
String name(); String getName();
/** /**
* Gets the commit id for the head of the branch. * Gets the commit id for the head of the branch.

View file

@ -33,5 +33,5 @@ public interface GitDBTransaction extends GitDBBranch {
* *
* @return the transaction name * @return the transaction name
*/ */
String name(); String getName();
} }

View file

@ -23,6 +23,7 @@ package net.kemitix.gitdb.impl;
import com.github.zafarkhaja.semver.Version; import com.github.zafarkhaja.semver.Version;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.kemitix.gitdb.GitDBBranch; import net.kemitix.gitdb.GitDBBranch;
import net.kemitix.gitdb.GitDBTransaction; import net.kemitix.gitdb.GitDBTransaction;
@ -48,6 +49,7 @@ class GitDBBranchImpl implements GitDBBranch {
private final GitDBRepo gitDBRepo; private final GitDBRepo gitDBRepo;
private final String userName; private final String userName;
private final String userEmailAddress; private final String userEmailAddress;
@Getter
private final String name; private final String name;
private static GitDBBranch select( private static GitDBBranch select(
@ -83,8 +85,8 @@ class GitDBBranchImpl implements GitDBBranch {
@Override @Override
public GitDBBranch put(final String key, final String value) throws IOException { public GitDBBranch put(final String key, final String value) throws IOException {
final ObjectId newTree = gitDBRepo.writeValue(branchRef, KEY_PREFIX + key, value); final ObjectId newTree = gitDBRepo.writeValue(branchRef, KEY_PREFIX + key, value);
final Ref newBranch = final String message = String.format("Add key [%s] = [%s]", key, value);
gitDBRepo.writeCommit(branchRef, newTree, commitMessageForAdd(key, value), userName, userEmailAddress); final Ref newBranch = gitDBRepo.writeCommit(branchRef, newTree, message, userName, userEmailAddress);
return select(newBranch, gitDBRepo, userName, userEmailAddress); return select(newBranch, gitDBRepo, userName, userEmailAddress);
} }
@ -95,7 +97,7 @@ class GitDBBranchImpl implements GitDBBranch {
final Ref newBranch = final Ref newBranch =
gitDBRepo.writeCommit( gitDBRepo.writeCommit(
branchRef, newTree.get(), branchRef, newTree.get(),
commitMessageForRemove(key), String.format("Remove Key [%s]", key),
userName, userName,
userEmailAddress); userEmailAddress);
return select(newBranch, gitDBRepo, userName, userEmailAddress); return select(newBranch, gitDBRepo, userName, userEmailAddress);
@ -121,22 +123,9 @@ class GitDBBranchImpl implements GitDBBranch {
return transaction(UUID.randomUUID().toString()); return transaction(UUID.randomUUID().toString());
} }
@Override
public String name() {
return name;
}
@Override @Override
public String getCommitId() { public String getCommitId() {
return branchRef.getObjectId().name(); return branchRef.getObjectId().name();
} }
private String commitMessageForAdd(final String key, final String value) {
return String.format("Add key [%s] = [%s]", key, value);
}
private String commitMessageForRemove(final String key) {
return String.format("Remove Key [%s]", key);
}
} }

View file

@ -71,8 +71,8 @@ class GitDBTransactionImpl implements GitDBTransaction {
} }
@Override @Override
public String name() { public String getName() {
return branch.name(); return branch.getName();
} }
@Override @Override

View file

@ -324,7 +324,7 @@ class GitDBTest implements WithAssertions {
final GitDBTransaction transaction = gitDBBranch.transaction(name); final GitDBTransaction transaction = gitDBBranch.transaction(name);
//then //then
assertThat(transaction).isNotNull(); assertThat(transaction).isNotNull();
assertThat(transaction.name()).isEqualTo(name); assertThat(transaction.getName()).isEqualTo(name);
} }
// When starting an anonymous transaction then a GitDbTransaction is returned // When starting an anonymous transaction then a GitDbTransaction is returned
@ -336,7 +336,7 @@ class GitDBTest implements WithAssertions {
final GitDBTransaction transaction = gitDBBranch.transaction(); final GitDBTransaction transaction = gitDBBranch.transaction();
//then //then
assertThat(transaction).isNotNull(); assertThat(transaction).isNotNull();
assertThat(transaction.name()).isNotNull(); assertThat(transaction.getName()).isNotNull();
} }
// When starting an anonymous transaction then original branch is unchanged // When starting an anonymous transaction then original branch is unchanged
@ -473,7 +473,7 @@ class GitDBTest implements WithAssertions {
//then //then
assertThat(secondTransaction).isNotNull(); assertThat(secondTransaction).isNotNull();
assertThat(secondTransaction).isNotSameAs(firstTransaction); assertThat(secondTransaction).isNotSameAs(firstTransaction);
assertThat(secondTransaction.name()).isEqualTo(name); assertThat(secondTransaction.getName()).isEqualTo(name);
} }
// Given a GitDbTransaction handle with a added, updated and removed keys // Given a GitDbTransaction handle with a added, updated and removed keys