From 00f840dcd1fc53b3face0d824af0eb9de9d19f08 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Fri, 7 Jun 2019 12:12:44 +0900 Subject: [PATCH] Consistently use "!isEmpty()" to detect non-empty list Replace "size() > 0" with "!isEmpty()" where appropriate. In the Status implementation we can drop the check; the subsequent loop will only execute when the list is non-empty anyway. Change-Id: I355aff551a603373e702a9d44304f087b476263c Signed-off-by: David Pursehouse --- .../org/eclipse/jgit/lfs/server/TransferHandler.java | 4 ++-- .../src/org/eclipse/jgit/pgm/Checkout.java | 2 +- .../src/org/eclipse/jgit/pgm/LsFiles.java | 2 +- .../src/org/eclipse/jgit/pgm/LsTree.java | 2 +- .../src/org/eclipse/jgit/pgm/Reset.java | 2 +- .../src/org/eclipse/jgit/pgm/Status.java | 2 +- .../tst/org/eclipse/jgit/api/CleanCommandTest.java | 10 +++++----- .../src/org/eclipse/jgit/api/LogCommand.java | 2 +- .../src/org/eclipse/jgit/api/RebaseCommand.java | 4 ++-- .../src/org/eclipse/jgit/merge/ResolveMerger.java | 2 +- .../src/org/eclipse/jgit/transport/BundleWriter.java | 2 +- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/TransferHandler.java b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/TransferHandler.java index 4fea92e11..6c36661c3 100644 --- a/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/TransferHandler.java +++ b/org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/TransferHandler.java @@ -84,7 +84,7 @@ abstract class TransferHandler { @Override Body process() throws IOException { Response.Body body = new Response.Body(); - if (objects.size() > 0) { + if (!objects.isEmpty()) { body.objects = new ArrayList<>(); for (LfsObject o : objects) { addObjectInfo(body, o); @@ -122,7 +122,7 @@ abstract class TransferHandler { @Override Body process() throws IOException { Response.Body body = new Response.Body(); - if (objects.size() > 0) { + if (!objects.isEmpty()) { body.objects = new ArrayList<>(); for (LfsObject o : objects) { addObjectInfo(body, o); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java index 7e1737f87..3df37e51c 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java @@ -96,7 +96,7 @@ class Checkout extends TextBuiltin { try (Git git = new Git(db)) { CheckoutCommand command = git.checkout() .setProgressMonitor(new TextProgressMonitor(errw)); - if (paths.size() > 0) { + if (!paths.isEmpty()) { command.setStartPoint(name); if (paths.size() == 1 && paths.get(0).equals(".")) { //$NON-NLS-1$ command.setAllPaths(true); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsFiles.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsFiles.java index ef2584497..e3ed30dc4 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsFiles.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsFiles.java @@ -85,7 +85,7 @@ class LsFiles extends TextBuiltin { CanonicalTreeParser p = new CanonicalTreeParser(); p.reset(rw.getObjectReader(), c.getTree()); tw.reset(); // drop the first empty tree, which we do not need here - if (paths.size() > 0) { + if (!paths.isEmpty()) { tw.setFilter(PathFilterGroup.createFromStrings(paths)); } tw.addTree(p); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java index 2a2bb7cc9..19f2d7ae4 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java @@ -76,7 +76,7 @@ class LsTree extends TextBuiltin { protected void run() { try (TreeWalk walk = new TreeWalk(db)) { walk.reset(); // drop the first empty tree, which we do not need here - if (paths.size() > 0) { + if (!paths.isEmpty()) { walk.setFilter(PathFilterGroup.createFromStrings(paths)); } walk.setRecursive(recursive); diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java index b3e81c6d6..e1a290731 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java @@ -80,7 +80,7 @@ class Reset extends TextBuiltin { try (Git git = new Git(db)) { ResetCommand command = git.reset(); command.setRef(commit); - if (paths.size() > 0) { + if (!paths.isEmpty()) { for (String path : paths) { command.addPath(path); } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java index 8b187587b..c3887fe9c 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java @@ -93,7 +93,7 @@ class Status extends TextBuiltin { protected void run() { try (Git git = new Git(db)) { StatusCommand statusCommand = git.status(); - if (filterPaths != null && filterPaths.size() > 0) { + if (filterPaths != null) { for (String path : filterPaths) { statusCommand.addPath(path); } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java index 4eeaf4d6e..c9852e8b8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java @@ -98,7 +98,7 @@ public class CleanCommandTest extends RepositoryTestCase { StatusCommand command = git.status(); Status status = command.call(); Set files = status.getUntracked(); - assertTrue(files.size() > 0); + assertFalse(files.isEmpty()); // run clean Set cleanedFiles = git.clean().call(); @@ -120,7 +120,7 @@ public class CleanCommandTest extends RepositoryTestCase { StatusCommand command = git.status(); Status status = command.call(); Set files = status.getUntracked(); - assertTrue(files.size() > 0); + assertFalse(files.isEmpty()); // run clean Set cleanedFiles = git.clean().setCleanDirectories(true).call(); @@ -143,7 +143,7 @@ public class CleanCommandTest extends RepositoryTestCase { StatusCommand command = git.status(); Status status = command.call(); Set files = status.getUntracked(); - assertTrue(files.size() > 0); + assertFalse(files.isEmpty()); // run clean with setPaths Set paths = new TreeSet<>(); @@ -164,7 +164,7 @@ public class CleanCommandTest extends RepositoryTestCase { StatusCommand command = git.status(); Status status = command.call(); Set files = status.getUntracked(); - assertTrue(files.size() > 0); + assertFalse(files.isEmpty()); // run clean Set cleanedFiles = git.clean().setDryRun(true).call(); @@ -186,7 +186,7 @@ public class CleanCommandTest extends RepositoryTestCase { StatusCommand command = git.status(); Status status = command.call(); Set files = status.getUntracked(); - assertTrue(files.size() > 0); + assertFalse(files.isEmpty()); // run clean Set cleanedFiles = git.clean().setDryRun(true) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java index 9b8016ce2..66de8ae13 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java @@ -133,7 +133,7 @@ public class LogCommand extends GitCommand> { @Override public Iterable call() throws GitAPIException, NoHeadException { checkCallable(); - if (pathFilters.size() > 0) + if (!pathFilters.isEmpty()) walk.setTreeFilter(AndTreeFilter.create( PathFilterGroup.create(pathFilters), TreeFilter.ANY_DIFF)); if (skip > -1 && maxCount > -1) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index cdd1b80bb..593874c12 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -490,7 +490,7 @@ public class RebaseCommand extends GitCommand { resetSoftToParent(); List steps = repo.readRebaseTodo( rebaseState.getPath(GIT_REBASE_TODO), false); - RebaseTodoLine nextStep = steps.size() > 0 ? steps.get(0) : null; + RebaseTodoLine nextStep = steps.isEmpty() ? null : steps.get(0); File messageFixupFile = rebaseState.getFile(MESSAGE_FIXUP); File messageSquashFile = rebaseState.getFile(MESSAGE_SQUASH); if (isSquash && messageFixupFile.exists()) @@ -1083,7 +1083,7 @@ public class RebaseCommand extends GitCommand { repo.writeRebaseTodoFile(rebaseState.getPath(GIT_REBASE_TODO), todoLines, false); - if (poppedLines.size() > 0) { + if (!poppedLines.isEmpty()) { repo.writeRebaseTodoFile(rebaseState.getPath(DONE), poppedLines, true); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java index b69327a9b..0c3d3fec2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java @@ -1190,7 +1190,7 @@ public class ResolveMerger extends ThreeWayMerger { * otherwise */ public boolean failed() { - return failingPaths.size() > 0; + return !failingPaths.isEmpty(); } /** diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java index a09b1ff1d..d1db51eca 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java @@ -227,7 +227,7 @@ public class BundleWriter { exc.add(r.getId()); packWriter.setIndexDisabled(true); packWriter.setDeltaBaseAsOffset(true); - packWriter.setThin(exc.size() > 0); + packWriter.setThin(!exc.isEmpty()); packWriter.setReuseValidatingObjects(false); if (exc.isEmpty()) { packWriter.setTagTargets(tagTargets);