]> source.dussan.org Git - jgit.git/commitdiff
Consistently use "!isEmpty()" to detect non-empty list 83/143483/1
authorDavid Pursehouse <david.pursehouse@gmail.com>
Fri, 7 Jun 2019 03:12:44 +0000 (12:12 +0900)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Fri, 7 Jun 2019 03:12:44 +0000 (12:12 +0900)
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 <david.pursehouse@gmail.com>
org.eclipse.jgit.lfs.server/src/org/eclipse/jgit/lfs/server/TransferHandler.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Checkout.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsFiles.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Reset.java
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Status.java
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/api/LogCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java

index 4fea92e111e55ecb95a2afade4b485632347c89a..6c36661c3ea9cae68a637d6a42eaebafd660d2db 100644 (file)
@@ -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);
index 7e1737f872d7e63c5bd79d851f9d7159a2eeb875..3df37e51c3a864a8f3e2988186e649013cbd9eb6 100644 (file)
@@ -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);
index ef25844973392e5a4c56a7e005f4f9ea6083ee79..e3ed30dc40a00bc29a4a34ee5340a02a07d73790 100644 (file)
@@ -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);
index 2a2bb7cc91c58bc080d91afdc25ca1920cc55161..19f2d7ae4f84b3b9cc195dc5cedb99a5e37077b9 100644 (file)
@@ -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);
index b3e81c6d65239e967d4524939d1f1e44ec993a76..e1a290731c552a9f173613105ecd9ef3161b1b10 100644 (file)
@@ -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);
                                }
index 8b187587bc7b4c6d14e5a54605fc45727b314859..c3887fe9c3bf7cbf5291e6b0d6bcafbc4b00e095 100644 (file)
@@ -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);
                                }
index 4eeaf4d6e405dec0f9ebd9e022662a88d4628044..c9852e8b8328b5ea9062a294df2932a3604b7472 100644 (file)
@@ -98,7 +98,7 @@ public class CleanCommandTest extends RepositoryTestCase {
                StatusCommand command = git.status();
                Status status = command.call();
                Set<String> files = status.getUntracked();
-               assertTrue(files.size() > 0);
+               assertFalse(files.isEmpty());
 
                // run clean
                Set<String> cleanedFiles = git.clean().call();
@@ -120,7 +120,7 @@ public class CleanCommandTest extends RepositoryTestCase {
                StatusCommand command = git.status();
                Status status = command.call();
                Set<String> files = status.getUntracked();
-               assertTrue(files.size() > 0);
+               assertFalse(files.isEmpty());
 
                // run clean
                Set<String> cleanedFiles = git.clean().setCleanDirectories(true).call();
@@ -143,7 +143,7 @@ public class CleanCommandTest extends RepositoryTestCase {
                StatusCommand command = git.status();
                Status status = command.call();
                Set<String> files = status.getUntracked();
-               assertTrue(files.size() > 0);
+               assertFalse(files.isEmpty());
 
                // run clean with setPaths
                Set<String> paths = new TreeSet<>();
@@ -164,7 +164,7 @@ public class CleanCommandTest extends RepositoryTestCase {
                StatusCommand command = git.status();
                Status status = command.call();
                Set<String> files = status.getUntracked();
-               assertTrue(files.size() > 0);
+               assertFalse(files.isEmpty());
 
                // run clean
                Set<String> cleanedFiles = git.clean().setDryRun(true).call();
@@ -186,7 +186,7 @@ public class CleanCommandTest extends RepositoryTestCase {
                StatusCommand command = git.status();
                Status status = command.call();
                Set<String> files = status.getUntracked();
-               assertTrue(files.size() > 0);
+               assertFalse(files.isEmpty());
 
                // run clean
                Set<String> cleanedFiles = git.clean().setDryRun(true)
index 9b8016ce2021f609eb9725b78cbd17687f274c51..66de8ae13111eb73d4aee9280092cff0056bf2ab 100644 (file)
@@ -133,7 +133,7 @@ public class LogCommand extends GitCommand<Iterable<RevCommit>> {
        @Override
        public Iterable<RevCommit> 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)
index cdd1b80bb49374710a7131e935e5328a5c0e8750..593874c12176c766151e22ed3e51b0fe85fd3523 100644 (file)
@@ -490,7 +490,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
                        resetSoftToParent();
                        List<RebaseTodoLine> 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<RebaseResult> {
 
                repo.writeRebaseTodoFile(rebaseState.getPath(GIT_REBASE_TODO),
                                todoLines, false);
-               if (poppedLines.size() > 0) {
+               if (!poppedLines.isEmpty()) {
                        repo.writeRebaseTodoFile(rebaseState.getPath(DONE), poppedLines,
                                        true);
                }
index b69327a9b3caec2478d4ba3351467f087dd75390..0c3d3fec26667aa00542ebc0cf4ec435f6874443 100644 (file)
@@ -1190,7 +1190,7 @@ public class ResolveMerger extends ThreeWayMerger {
         *         otherwise
         */
        public boolean failed() {
-               return failingPaths.size() > 0;
+               return !failingPaths.isEmpty();
        }
 
        /**
index a09b1ff1d238c1dd1770ca55e9266b282d5ea61b..d1db51eca64544128113b4cb7355e5edff8837a8 100644 (file)
@@ -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);