From 2305c0ed1b6b4e752a3274d3c57a3132f158afa8 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Fri, 15 Jun 2018 10:07:23 +0100 Subject: [PATCH] Extract NamedRevBlob to top level class --- .../net/kemitix/gitdb/impl/GitTreeReader.java | 28 +-------- .../net/kemitix/gitdb/impl/KeyRemover.java | 6 +- .../net/kemitix/gitdb/impl/NamedRevBlob.java | 57 +++++++++++++++++++ 3 files changed, 62 insertions(+), 29 deletions(-) create mode 100644 src/main/java/net/kemitix/gitdb/impl/NamedRevBlob.java diff --git a/src/main/java/net/kemitix/gitdb/impl/GitTreeReader.java b/src/main/java/net/kemitix/gitdb/impl/GitTreeReader.java index 05e4911..31e396e 100644 --- a/src/main/java/net/kemitix/gitdb/impl/GitTreeReader.java +++ b/src/main/java/net/kemitix/gitdb/impl/GitTreeReader.java @@ -22,12 +22,9 @@ package net.kemitix.gitdb.impl; import lombok.AccessLevel; -import lombok.Getter; import lombok.RequiredArgsConstructor; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.revwalk.RevBlob; import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.filter.PathFilter; @@ -66,7 +63,8 @@ class GitTreeReader { while (treeWalk.next()) { builder.add(new NamedRevBlob( treeWalk.getNameString(), - new RevWalk(repository).lookupBlob(treeWalk.getObjectId(0)))); + new RevWalk(repository).lookupBlob(treeWalk.getObjectId(0)), + repository)); } return builder.build(); } @@ -82,26 +80,4 @@ class GitTreeReader { return this; } - /** - * Represents the key/value pairs read from the tree. - */ - @Getter(AccessLevel.PACKAGE) - @RequiredArgsConstructor(access = AccessLevel.PACKAGE) - protected class NamedRevBlob { - - private final String name; - private final RevBlob revBlob; - - /** - * Converts the blob to a String. - * - * @return a string - * @throws IOException of there was an error reading the blob - */ - String blobAsString() throws IOException { - return new String(repository.open(revBlob.getId(), Constants.OBJ_BLOB).getBytes()); - } - - } - } diff --git a/src/main/java/net/kemitix/gitdb/impl/KeyRemover.java b/src/main/java/net/kemitix/gitdb/impl/KeyRemover.java index 81a8754..69f9d86 100644 --- a/src/main/java/net/kemitix/gitdb/impl/KeyRemover.java +++ b/src/main/java/net/kemitix/gitdb/impl/KeyRemover.java @@ -50,7 +50,7 @@ class KeyRemover { * @param removed the boolean to update * @return a Consumer */ - private static Consumer flagIfFound(final String key, final AtomicBoolean removed) { + private static Consumer flagIfFound(final String key, final AtomicBoolean removed) { return nvb -> { if (nvb.getName().equals(key)) { removed.set(true); @@ -64,7 +64,7 @@ class KeyRemover { * @param key the key to match * @return a Predicate */ - private static Predicate isNotKey(final String key) { + private static Predicate isNotKey(final String key) { return item -> !item.getName().equals(key); } @@ -74,7 +74,7 @@ class KeyRemover { * @param treeFormatter the tree formatter to add to * @return a Consumer */ - private static Consumer addToTree(final TreeFormatter treeFormatter) { + private static Consumer addToTree(final TreeFormatter treeFormatter) { return item -> treeFormatter.append(item.getName(), item.getRevBlob()); } diff --git a/src/main/java/net/kemitix/gitdb/impl/NamedRevBlob.java b/src/main/java/net/kemitix/gitdb/impl/NamedRevBlob.java new file mode 100644 index 0000000..09a39ec --- /dev/null +++ b/src/main/java/net/kemitix/gitdb/impl/NamedRevBlob.java @@ -0,0 +1,57 @@ +/* + The MIT License (MIT) + + Copyright (c) 2018 Paul Campbell + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software + and associated documentation files (the "Software"), to deal in the Software without restriction, + including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies + or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE + AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package net.kemitix.gitdb.impl; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.revwalk.RevBlob; + +import java.io.IOException; + +/** + * Represents the key/value pairs read from the tree. + * + * @author Paul Campbell (pcampbell@kemitix.net) + */ +@RequiredArgsConstructor(access = AccessLevel.PACKAGE) +class NamedRevBlob { + + @Getter + private final String name; + @Getter + private final RevBlob revBlob; + private final Repository repository; + + /** + * Converts the blob to a String. + * + * @return a string + * @throws IOException of there was an error reading the blob + */ + String blobAsString() throws IOException { + return new String(repository.open(revBlob.getId(), Constants.OBJ_BLOB).getBytes()); + } + +}