From 9b8c4765aecc79ddf6e774c73de44f01fa42236e Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 15 Jun 2018 19:20:34 +0100 Subject: [PATCH] Reduce method count for GitDBBranch --- .../java/net/kemitix/gitdb/GitDBBranch.java | 2 +- .../net/kemitix/gitdb/GitDBTransaction.java | 2 +- .../kemitix/gitdb/impl/GitDBBranchImpl.java | 21 +++++-------------- .../gitdb/impl/GitDBTransactionImpl.java | 4 ++-- .../net/kemitix/gitdb/test/GitDBTest.java | 6 +++--- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/kemitix/gitdb/GitDBBranch.java b/src/main/java/net/kemitix/gitdb/GitDBBranch.java index aa68421..ded2f61 100644 --- a/src/main/java/net/kemitix/gitdb/GitDBBranch.java +++ b/src/main/java/net/kemitix/gitdb/GitDBBranch.java @@ -93,7 +93,7 @@ public interface GitDBBranch { * * @return the branch name */ - String name(); + String getName(); /** * Gets the commit id for the head of the branch. diff --git a/src/main/java/net/kemitix/gitdb/GitDBTransaction.java b/src/main/java/net/kemitix/gitdb/GitDBTransaction.java index 139d0b9..0143fac 100644 --- a/src/main/java/net/kemitix/gitdb/GitDBTransaction.java +++ b/src/main/java/net/kemitix/gitdb/GitDBTransaction.java @@ -33,5 +33,5 @@ public interface GitDBTransaction extends GitDBBranch { * * @return the transaction name */ - String name(); + String getName(); } diff --git a/src/main/java/net/kemitix/gitdb/impl/GitDBBranchImpl.java b/src/main/java/net/kemitix/gitdb/impl/GitDBBranchImpl.java index 8be9f1f..e14485f 100644 --- a/src/main/java/net/kemitix/gitdb/impl/GitDBBranchImpl.java +++ b/src/main/java/net/kemitix/gitdb/impl/GitDBBranchImpl.java @@ -23,6 +23,7 @@ package net.kemitix.gitdb.impl; import com.github.zafarkhaja.semver.Version; import lombok.AccessLevel; +import lombok.Getter; import lombok.RequiredArgsConstructor; import net.kemitix.gitdb.GitDBBranch; import net.kemitix.gitdb.GitDBTransaction; @@ -48,6 +49,7 @@ class GitDBBranchImpl implements GitDBBranch { private final GitDBRepo gitDBRepo; private final String userName; private final String userEmailAddress; + @Getter private final String name; private static GitDBBranch select( @@ -83,8 +85,8 @@ class GitDBBranchImpl implements GitDBBranch { @Override public GitDBBranch put(final String key, final String value) throws IOException { final ObjectId newTree = gitDBRepo.writeValue(branchRef, KEY_PREFIX + key, value); - final Ref newBranch = - gitDBRepo.writeCommit(branchRef, newTree, commitMessageForAdd(key, value), userName, userEmailAddress); + final String message = String.format("Add key [%s] = [%s]", key, value); + final Ref newBranch = gitDBRepo.writeCommit(branchRef, newTree, message, userName, userEmailAddress); return select(newBranch, gitDBRepo, userName, userEmailAddress); } @@ -95,7 +97,7 @@ class GitDBBranchImpl implements GitDBBranch { final Ref newBranch = gitDBRepo.writeCommit( branchRef, newTree.get(), - commitMessageForRemove(key), + String.format("Remove Key [%s]", key), userName, userEmailAddress); return select(newBranch, gitDBRepo, userName, userEmailAddress); @@ -121,22 +123,9 @@ class GitDBBranchImpl implements GitDBBranch { return transaction(UUID.randomUUID().toString()); } - @Override - public String name() { - return name; - } - @Override public String getCommitId() { 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); - } - } diff --git a/src/main/java/net/kemitix/gitdb/impl/GitDBTransactionImpl.java b/src/main/java/net/kemitix/gitdb/impl/GitDBTransactionImpl.java index 916e396..ee81155 100644 --- a/src/main/java/net/kemitix/gitdb/impl/GitDBTransactionImpl.java +++ b/src/main/java/net/kemitix/gitdb/impl/GitDBTransactionImpl.java @@ -71,8 +71,8 @@ class GitDBTransactionImpl implements GitDBTransaction { } @Override - public String name() { - return branch.name(); + public String getName() { + return branch.getName(); } @Override diff --git a/src/test/java/net/kemitix/gitdb/test/GitDBTest.java b/src/test/java/net/kemitix/gitdb/test/GitDBTest.java index c68a10f..e52f65b 100644 --- a/src/test/java/net/kemitix/gitdb/test/GitDBTest.java +++ b/src/test/java/net/kemitix/gitdb/test/GitDBTest.java @@ -324,7 +324,7 @@ class GitDBTest implements WithAssertions { final GitDBTransaction transaction = gitDBBranch.transaction(name); //then assertThat(transaction).isNotNull(); - assertThat(transaction.name()).isEqualTo(name); + assertThat(transaction.getName()).isEqualTo(name); } // When starting an anonymous transaction then a GitDbTransaction is returned @@ -336,7 +336,7 @@ class GitDBTest implements WithAssertions { final GitDBTransaction transaction = gitDBBranch.transaction(); //then assertThat(transaction).isNotNull(); - assertThat(transaction.name()).isNotNull(); + assertThat(transaction.getName()).isNotNull(); } // When starting an anonymous transaction then original branch is unchanged @@ -473,7 +473,7 @@ class GitDBTest implements WithAssertions { //then assertThat(secondTransaction).isNotNull(); 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