Browse Source

Use isEmpty() instead of size()==0 where possible

Change-Id: I97f1367a2ea9f1f6146e264c27c3981b842f2a26
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-5.4
Carsten Hammer 6 years ago committed by Matthias Sohn
parent
commit
6a4c77e619
  1. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/PathTreeFilterHandler.java
  2. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java
  3. 9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
  4. 2
      org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java
  5. 4
      org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
  6. 2
      org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
  7. 2
      org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
  8. 2
      org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
  9. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
  10. 2
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java
  11. 2
      org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
  12. 2
      org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java
  13. 3
      org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/opt/PathTreeFilterHandler.java

@ -96,7 +96,7 @@ public class PathTreeFilterHandler extends OptionHandler<TreeFilter> {
filters.add(PathFilter.create(path)); filters.add(PathFilter.create(path));
} }
if (filters.size() == 0) if (filters.isEmpty())
return 0; return 0;
if (filters.size() == 1) { if (filters.size() == 1) {
setter.addValue(filters.get(0)); setter.addValue(filters.get(0));

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CleanCommandTest.java

@ -128,7 +128,7 @@ public class CleanCommandTest extends RepositoryTestCase {
status = git.status().call(); status = git.status().call();
files = status.getUntracked(); files = status.getUntracked();
assertTrue(files.size() == 0); assertTrue(files.isEmpty());
assertTrue(cleanedFiles.contains("File2.txt")); assertTrue(cleanedFiles.contains("File2.txt"));
assertTrue(cleanedFiles.contains("File3.txt")); assertTrue(cleanedFiles.contains("File3.txt"));
assertTrue(!cleanedFiles.contains("sub-noclean/File1.txt")); assertTrue(!cleanedFiles.contains("sub-noclean/File1.txt"));

9
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java

@ -45,7 +45,6 @@
package org.eclipse.jgit.lib; package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
@ -63,7 +62,8 @@ public class ReflogConfigTest extends RepositoryTestCase {
// check that there are no entries in the reflog and turn off writing // check that there are no entries in the reflog and turn off writing
// reflogs // reflogs
assertEquals(0, db.getReflogReader(Constants.HEAD).getReverseEntries().size()); assertTrue(db.getReflogReader(Constants.HEAD).getReverseEntries()
.isEmpty());
final FileBasedConfig cfg = db.getConfig(); final FileBasedConfig cfg = db.getConfig();
cfg.setBoolean("core", null, "logallrefupdates", false); cfg.setBoolean("core", null, "logallrefupdates", false);
cfg.save(); cfg.save();
@ -72,9 +72,8 @@ public class ReflogConfigTest extends RepositoryTestCase {
// written // written
commit("A Commit\n", commitTime, tz); commit("A Commit\n", commitTime, tz);
commitTime += 60 * 1000; commitTime += 60 * 1000;
assertTrue( assertTrue("Reflog for HEAD still contain no entry", db
"Reflog for HEAD still contain no entry", .getReflogReader(Constants.HEAD).getReverseEntries().isEmpty());
db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 0);
// set the logAllRefUpdates parameter to true and check it // set the logAllRefUpdates parameter to true and check it
cfg.setBoolean("core", null, "logallrefupdates", true); cfg.setBoolean("core", null, "logallrefupdates", true);

2
org.eclipse.jgit/src/org/eclipse/jgit/api/CommitCommand.java

@ -282,7 +282,7 @@ public class CommitCommand extends GitCommand<RevCommit> {
ru.setRefLogMessage(reflogComment, false); ru.setRefLogMessage(reflogComment, false);
} else { } else {
String prefix = amend ? "commit (amend): " //$NON-NLS-1$ String prefix = amend ? "commit (amend): " //$NON-NLS-1$
: parents.size() == 0 ? "commit (initial): " //$NON-NLS-1$ : parents.isEmpty() ? "commit (initial): " //$NON-NLS-1$
: "commit: "; //$NON-NLS-1$ : "commit: "; //$NON-NLS-1$
ru.setRefLogMessage(prefix + revCommit.getShortMessage(), ru.setRefLogMessage(prefix + revCommit.getShortMessage(),
false); false);

4
org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java

@ -246,9 +246,9 @@ public class DescribeCommand extends GitCommand<String> {
}; };
private Optional<Ref> getBestMatch(List<Ref> tags) { private Optional<Ref> getBestMatch(List<Ref> tags) {
if (tags == null || tags.size() == 0) { if (tags == null || tags.isEmpty()) {
return Optional.empty(); return Optional.empty();
} else if (matchers.size() == 0) { } else if (matchers.isEmpty()) {
Collections.sort(tags, TAG_TIE_BREAKER); Collections.sort(tags, TAG_TIE_BREAKER);
return Optional.of(tags.get(0)); return Optional.of(tags.get(0));
} else { } else {

2
org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java

@ -362,7 +362,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
List<RebaseTodoLine> steps = repo.readRebaseTodo( List<RebaseTodoLine> steps = repo.readRebaseTodo(
rebaseState.getPath(GIT_REBASE_TODO), false); rebaseState.getPath(GIT_REBASE_TODO), false);
if (steps.size() == 0) { if (steps.isEmpty()) {
return finishRebase(walk.parseCommit(repo.resolve(Constants.HEAD)), false); return finishRebase(walk.parseCommit(repo.resolve(Constants.HEAD)), false);
} }
if (isInteractive()) { if (isInteractive()) {

2
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java

@ -1063,7 +1063,7 @@ public class DiffFormatter implements AutoCloseable {
entry.newId = id; entry.newId = id;
break; break;
} }
} else if (ids.size() == 0) } else if (ids.isEmpty())
throw new MissingObjectException(id, Constants.OBJ_BLOB); throw new MissingObjectException(id, Constants.OBJ_BLOB);
else else
throw new AmbiguousObjectException(id, ids); throw new AmbiguousObjectException(id, ids);

2
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java vendored

@ -632,7 +632,7 @@ public class DirCacheCheckout {
if (!builder.commit()) if (!builder.commit())
throw new IndexWriteException(); throw new IndexWriteException();
} }
return toBeDeleted.size() == 0; return toBeDeleted.isEmpty();
} }
private void checkoutGitlink(String path, DirCacheEntry entry) private void checkoutGitlink(String path, DirCacheEntry entry)

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

@ -745,7 +745,7 @@ public class RefDirectory extends RefDatabase {
for (LockFile ol : heldLocks.values()) { for (LockFile ol : heldLocks.values()) {
ol.requireLock(); ol.requireLock();
} }
if (refs.size() == 0) { if (refs.isEmpty()) {
return null; return null;
} }
FS fs = parent.getFS(); FS fs = parent.getFS();

2
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

@ -923,7 +923,7 @@ public abstract class Repository implements AutoCloseable {
AbbreviatedObjectId id = AbbreviatedObjectId.fromString(revstr); AbbreviatedObjectId id = AbbreviatedObjectId.fromString(revstr);
try (ObjectReader reader = newObjectReader()) { try (ObjectReader reader = newObjectReader()) {
Collection<ObjectId> matches = reader.resolve(id); Collection<ObjectId> matches = reader.resolve(id);
if (matches.size() == 0) if (matches.isEmpty())
return null; return null;
else if (matches.size() == 1) else if (matches.size() == 1)
return matches.iterator().next(); return matches.iterator().next();

2
org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java

@ -1179,7 +1179,7 @@ public class ResolveMerger extends ThreeWayMerger {
* fail. * fail.
*/ */
public Map<String, MergeFailureReason> getFailingPaths() { public Map<String, MergeFailureReason> getFailingPaths() {
return (failingPaths.size() == 0) ? null : failingPaths; return failingPaths.isEmpty() ? null : failingPaths;
} }
/** /**

2
org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevWalk.java

@ -506,7 +506,7 @@ public class RevWalk implements Iterable<RevCommit>, AutoCloseable {
if (sorting.size() > 1) if (sorting.size() > 1)
sorting.remove(RevSort.NONE); sorting.remove(RevSort.NONE);
else if (sorting.size() == 0) else if (sorting.isEmpty())
sorting.add(RevSort.NONE); sorting.add(RevSort.NONE);
} }

3
org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java

@ -229,8 +229,9 @@ public class BundleWriter {
packWriter.setDeltaBaseAsOffset(true); packWriter.setDeltaBaseAsOffset(true);
packWriter.setThin(exc.size() > 0); packWriter.setThin(exc.size() > 0);
packWriter.setReuseValidatingObjects(false); packWriter.setReuseValidatingObjects(false);
if (exc.size() == 0) if (exc.isEmpty()) {
packWriter.setTagTargets(tagTargets); packWriter.setTagTargets(tagTargets);
}
packWriter.preparePack(monitor, inc, exc); packWriter.preparePack(monitor, inc, exc);
final Writer w = new OutputStreamWriter(os, UTF_8); final Writer w = new OutputStreamWriter(os, UTF_8);

Loading…
Cancel
Save