Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hammer2019-05-21 15:04:18 +0000
committerMatthias Sohn2019-12-14 19:42:03 +0000
commit74bc50125d3a2cb0a7eb8c32118b3f9a9530a361 (patch)
tree48e86457ef252be344ece68d9558f72fd23b911c
parent1b3a555f667712ece7f17f009b5444862cbac54f (diff)
downloadjgit-74bc50125d3a2cb0a7eb8c32118b3f9a9530a361.tar.gz
jgit-74bc50125d3a2cb0a7eb8c32118b3f9a9530a361.tar.xz
jgit-74bc50125d3a2cb0a7eb8c32118b3f9a9530a361.zip
Replace chain of if statements with switch
and switch over strings where possible. Sometimes if statements are chained and form a series of comparisons against constants. Using switch statements improves readability. Bug: 545856 Change-Id: Iacb78956ee5c20db4d793e6b668508ec67466606 Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java7
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AmazonS3Client.java23
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java50
-rw-r--r--org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java8
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java83
-rw-r--r--org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtCredentialsProvider.java9
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java94
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommit.java20
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/AdvertiseRefsHookChain.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PostReceiveHookChain.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PreReceiveHookChain.java8
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/GitDateParser.java49
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java11
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java10
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/sha1/SHA1.java9
20 files changed, 281 insertions, 166 deletions
diff --git a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java
index befb7f62ac..1d9dca73d0 100644
--- a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java
+++ b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java
@@ -190,11 +190,12 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase {
}
protected String cmdString(String... cmds) {
- if (cmds.length == 0)
+ switch (cmds.length) {
+ case 0:
return "";
- else if (cmds.length == 1)
+ case 1:
return "\"" + escapeJava(cmds[0]) + "\"";
- else {
+ default:
StringBuilder sb = new StringBuilder(cmdString(cmds[0]));
for (int i=1; i<cmds.length; i++) {
sb.append(", ");
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AmazonS3Client.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AmazonS3Client.java
index f4f8d8f50f..9dd4eb5f1d 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AmazonS3Client.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/AmazonS3Client.java
@@ -86,7 +86,11 @@ class AmazonS3Client extends TextBuiltin {
protected void run() throws Exception {
final AmazonS3 s3 = new AmazonS3(properties());
- if ("get".equals(op)) { //$NON-NLS-1$
+ if (op == null) {
+ throw die(MessageFormat.format(CLIText.get().unsupportedOperation, op));
+ }
+ switch (op) {
+ case "get": //$NON-NLS-1$
final URLConnection c = s3.get(bucket, key);
int len = c.getContentLength();
try (InputStream in = c.getInputStream()) {
@@ -103,22 +107,25 @@ class AmazonS3Client extends TextBuiltin {
}
outs.flush();
}
-
- } else if ("ls".equals(op) || "list".equals(op)) { //$NON-NLS-1$//$NON-NLS-2$
+ break;
+ case "ls": //$NON-NLS-1$
+ case "list": //$NON-NLS-1$
for (String k : s3.list(bucket, key))
outw.println(k);
-
- } else if ("rm".equals(op) || "delete".equals(op)) { //$NON-NLS-1$ //$NON-NLS-2$
+ break;
+ case "rm": //$NON-NLS-1$
+ case "delete": //$NON-NLS-1$
s3.delete(bucket, key);
-
- } else if ("put".equals(op)) { //$NON-NLS-1$
+ break;
+ case "put": //$NON-NLS-1$
try (OutputStream os = s3.beginPut(bucket, key, null, null)) {
final byte[] tmp = new byte[2048];
int n;
while ((n = ins.read(tmp)) > 0)
os.write(tmp, 0, n);
}
- } else {
+ break;
+ default:
throw die(MessageFormat.format(CLIText.get().unsupportedOperation, op));
}
}
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java
index 58138fa03b..cdf9541012 100644
--- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Remote.java
@@ -93,33 +93,35 @@ class Remote extends TextBuiltin {
RemoteListCommand cmd = git.remoteList();
List<RemoteConfig> remotes = cmd.call();
print(remotes);
- } else if ("add".equals(command)) { //$NON-NLS-1$
- RemoteAddCommand cmd = git.remoteAdd();
- cmd.setName(name);
- cmd.setUri(new URIish(uri));
- cmd.call();
- } else if ("remove".equals(command) || "rm".equals(command)) { //$NON-NLS-1$ //$NON-NLS-2$
- RemoteRemoveCommand cmd = git.remoteRemove();
- cmd.setRemoteName(name);
- cmd.call();
- } else if ("set-url".equals(command)) { //$NON-NLS-1$
- RemoteSetUrlCommand cmd = git.remoteSetUrl();
- cmd.setRemoteName(name);
- cmd.setRemoteUri(new URIish(uri));
- cmd.setUriType(push ? UriType.PUSH : UriType.FETCH);
- cmd.call();
- } else if ("update".equals(command)) { //$NON-NLS-1$
- // reuse fetch command for basic implementation of remote update
+ return;
+ }
+ switch (command) {
+ case "add": //$NON-NLS-1$
+ RemoteAddCommand add = git.remoteAdd();
+ add.setName(name);
+ add.setUri(new URIish(uri));
+ add.call();
+ break;
+ case "remove": //$NON-NLS-1$
+ case "rm": //$NON-NLS-1$
+ RemoteRemoveCommand rm = git.remoteRemove();
+ rm.setRemoteName(name);
+ rm.call();
+ break;
+ case "set-url": //$NON-NLS-1$
+ RemoteSetUrlCommand remoteSetUrl = git.remoteSetUrl();
+ remoteSetUrl.setRemoteName(name);
+ remoteSetUrl.setRemoteUri(new URIish(uri));
+ remoteSetUrl.setUriType(push ? UriType.PUSH : UriType.FETCH);
+ remoteSetUrl.call();
+ break;
+ case "update": //$NON-NLS-1$
Fetch fetch = new Fetch();
fetch.init(db, gitdir);
-
- // redirect the output stream
StringWriter osw = new StringWriter();
fetch.outw = new ThrowingPrintWriter(osw);
- // redirect the error stream
StringWriter esw = new StringWriter();
fetch.errw = new ThrowingPrintWriter(esw);
-
List<String> fetchArgs = new ArrayList<>();
if (verbose) {
fetchArgs.add("--verbose"); //$NON-NLS-1$
@@ -130,15 +132,13 @@ class Remote extends TextBuiltin {
if (name != null) {
fetchArgs.add(name);
}
-
fetch.execute(fetchArgs.toArray(new String[0]));
-
- // flush the streams
fetch.outw.flush();
fetch.errw.flush();
outw.println(osw.toString());
errw.println(esw.toString());
- } else {
+ break;
+ default:
throw new JGitInternalException(MessageFormat
.format(CLIText.get().unknownSubcommand, command));
}
diff --git a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java
index 79bd3faa01..be5eaa495d 100644
--- a/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java
+++ b/org.eclipse.jgit.ssh.apache/src/org/eclipse/jgit/internal/transport/sshd/JGitClientSession.java
@@ -251,12 +251,13 @@ public class JGitClientSession extends ClientSessionImpl {
.getProperty(SshConstants.HOST_KEY_ALGORITHMS);
if (hostKeyAlgorithms != null && !hostKeyAlgorithms.isEmpty()) {
char first = hostKeyAlgorithms.charAt(0);
- if (first == '+') {
+ switch (first) {
+ case '+':
// Additions make not much sense -- it's either in
// defaultSignatures already, or we have no implementation for
// it. No point in proposing it.
return String.join(",", defaultSignatures); //$NON-NLS-1$
- } else if (first == '-') {
+ case '-':
// This takes wildcard patterns!
removeFromList(defaultSignatures,
SshConstants.HOST_KEY_ALGORITHMS,
@@ -269,7 +270,7 @@ public class JGitClientSession extends ClientSessionImpl {
hostKeyAlgorithms));
}
return String.join(",", defaultSignatures); //$NON-NLS-1$
- } else {
+ default:
// Default is overridden -- only accept the ones for which we do
// have an implementation.
List<String> newNames = filteredList(defaultSignatures,
@@ -282,6 +283,7 @@ public class JGitClientSession extends ClientSessionImpl {
} else {
return String.join(",", newNames); //$NON-NLS-1$
}
+ break;
}
}
// No HostKeyAlgorithms; using default -- change order to put existing
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
index cfc275a7de..6e0762fe3d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsGarbageCollectorTest.java
@@ -169,12 +169,16 @@ public class DfsGarbageCollectorTest {
DfsPackFile garbage = null;
for (DfsPackFile pack : odb.getPacks()) {
DfsPackDescription d = pack.getPackDescription();
- if (d.getPackSource() == GC) {
+ switch (d.getPackSource()) {
+ case GC:
gc = pack;
- } else if (d.getPackSource() == UNREACHABLE_GARBAGE) {
+ break;
+ case UNREACHABLE_GARBAGE:
garbage = pack;
- } else {
+ break;
+ default:
fail("unexpected " + d.getPackSource());
+ break;
}
}
@@ -200,16 +204,20 @@ public class DfsGarbageCollectorTest {
boolean garbagePackFound = false;
for (DfsPackFile pack : odb.getPacks()) {
DfsPackDescription d = pack.getPackDescription();
- if (d.getPackSource() == GC) {
+ switch (d.getPackSource()) {
+ case GC:
gcPackFound = true;
assertTrue("has commit0", isObjectInPack(commit0, pack));
assertFalse("no commit1", isObjectInPack(commit1, pack));
- } else if (d.getPackSource() == UNREACHABLE_GARBAGE) {
+ break;
+ case UNREACHABLE_GARBAGE:
garbagePackFound = true;
assertFalse("no commit0", isObjectInPack(commit0, pack));
assertTrue("has commit1", isObjectInPack(commit1, pack));
- } else {
+ break;
+ default:
fail("unexpected " + d.getPackSource());
+ break;
}
}
assertTrue("gc pack found", gcPackFound);
@@ -240,16 +248,20 @@ public class DfsGarbageCollectorTest {
boolean garbagePackFound = false;
for (DfsPackFile pack : odb.getPacks()) {
DfsPackDescription d = pack.getPackDescription();
- if (d.getPackSource() == GC) {
+ switch (d.getPackSource()) {
+ case GC:
gcPackFound = true;
assertTrue("has commit0", isObjectInPack(commit0, pack));
assertFalse("no commit1", isObjectInPack(commit1, pack));
- } else if (d.getPackSource() == UNREACHABLE_GARBAGE) {
+ break;
+ case UNREACHABLE_GARBAGE:
garbagePackFound = true;
assertFalse("no commit0", isObjectInPack(commit0, pack));
assertTrue("has commit1", isObjectInPack(commit1, pack));
- } else {
+ break;
+ default:
fail("unexpected " + d.getPackSource());
+ break;
}
}
assertTrue("gc pack found", gcPackFound);
@@ -448,12 +460,16 @@ public class DfsGarbageCollectorTest {
long inputPacksSize = 32;
for (DfsPackFile pack : odb.getPacks()) {
DfsPackDescription d = pack.getPackDescription();
- if (d.getPackSource() == GC) {
+ switch (d.getPackSource()) {
+ case GC:
gcPackFound = true;
- } else if (d.getPackSource() == INSERT) {
+ break;
+ case INSERT:
insertPackFound = true;
- } else {
+ break;
+ default:
fail("unexpected " + d.getPackSource());
+ break;
}
inputPacksSize += d.getFileSize(PACK) - 32;
}
@@ -512,12 +528,16 @@ public class DfsGarbageCollectorTest {
long inputPacksSize = 32;
for (DfsPackFile pack : odb.getPacks()) {
DfsPackDescription d = pack.getPackDescription();
- if (d.getPackSource() == GC_REST) {
+ switch (d.getPackSource()) {
+ case GC_REST:
gcRestPackFound = true;
- } else if (d.getPackSource() == INSERT) {
+ break;
+ case INSERT:
insertPackFound = true;
- } else {
+ break;
+ default:
fail("unexpected " + d.getPackSource());
+ break;
}
inputPacksSize += d.getFileSize(PACK) - 32;
}
@@ -555,17 +575,22 @@ public class DfsGarbageCollectorTest {
long insertPackSize = 0;
for (DfsPackFile pack : odb.getPacks()) {
DfsPackDescription d = pack.getPackDescription();
- if (d.getPackSource() == GC) {
+ switch (d.getPackSource()) {
+ case GC:
gcPackFound = true;
gcPackSize = d.getFileSize(PACK);
- } else if (d.getPackSource() == GC_REST) {
+ break;
+ case GC_REST:
gcRestPackFound = true;
gcRestPackSize = d.getFileSize(PACK);
- } else if (d.getPackSource() == INSERT) {
+ break;
+ case INSERT:
insertPackFound = true;
insertPackSize = d.getFileSize(PACK);
- } else {
+ break;
+ default:
fail("unexpected " + d.getPackSource());
+ break;
}
}
assertTrue(gcPackFound);
@@ -583,16 +608,20 @@ public class DfsGarbageCollectorTest {
gcRestPackFound = false;
for (DfsPackFile pack : odb.getPacks()) {
DfsPackDescription d = pack.getPackDescription();
- if (d.getPackSource() == GC) {
+ switch (d.getPackSource()) {
+ case GC:
gcPackFound = true;
assertEquals(gcPackSize + insertPackSize - 32,
pack.getPackDescription().getEstimatedPackSize());
- } else if (d.getPackSource() == GC_REST) {
+ break;
+ case GC_REST:
gcRestPackFound = true;
assertEquals(gcRestPackSize + insertPackSize - 32,
pack.getPackDescription().getEstimatedPackSize());
- } else {
+ break;
+ default:
fail("unexpected " + d.getPackSource());
+ break;
}
}
assertTrue(gcPackFound);
@@ -629,18 +658,22 @@ public class DfsGarbageCollectorTest {
assertEquals(2, odb.getPacks().length);
for (DfsPackFile pack : odb.getPacks()) {
DfsPackDescription d = pack.getPackDescription();
- if (d.getPackSource() == GC) {
+ switch (d.getPackSource()) {
+ case GC:
// Even though just commit0 will end up in GC pack, because
// there is no good way to know that up front, both the pack
// sizes are considered while computing the estimated size of GC
// pack.
assertEquals(packSize0 + packSize1 - 32,
d.getEstimatedPackSize());
- } else if (d.getPackSource() == UNREACHABLE_GARBAGE) {
+ break;
+ case UNREACHABLE_GARBAGE:
// commit1 is moved to UNREACHABLE_GARBAGE pack.
assertEquals(packSize1, d.getEstimatedPackSize());
- } else {
+ break;
+ default:
fail("unexpected " + d.getPackSource());
+ break;
}
}
}
diff --git a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtCredentialsProvider.java b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtCredentialsProvider.java
index edf94cff44..22409a3b6d 100644
--- a/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtCredentialsProvider.java
+++ b/org.eclipse.jgit.ui/src/org/eclipse/jgit/awtui/AwtCredentialsProvider.java
@@ -108,10 +108,10 @@ public class AwtCredentialsProvider extends CredentialsProvider {
@Override
public boolean get(URIish uri, CredentialItem... items)
throws UnsupportedCredentialItem {
- if (items.length == 0) {
+ switch (items.length) {
+ case 0:
return true;
-
- } else if (items.length == 1) {
+ case 1:
final CredentialItem item = items[0];
if (item instanceof CredentialItem.InformationalMessage) {
@@ -141,8 +141,7 @@ public class AwtCredentialsProvider extends CredentialsProvider {
} else {
return interactive(uri, items);
}
-
- } else {
+ default:
return interactive(uri, items);
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java
index 106737805c..4e544d18e8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/blame/ReverseWalk.java
@@ -92,15 +92,19 @@ final class ReverseWalk extends RevWalk {
// visited first by BlameGenerator when considering candidates.
int cnt = children.length;
- if (cnt == 0)
+ switch (cnt) {
+ case 0:
children = new ReverseCommit[] { c };
- else if (cnt == 1)
+ break;
+ case 1:
children = new ReverseCommit[] { c, children[0] };
- else {
+ break;
+ default:
ReverseCommit[] n = new ReverseCommit[1 + cnt];
n[0] = c;
System.arraycopy(children, 0, n, 1, cnt);
children = n;
+ break;
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java
index febdb92091..4c652e583d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/ManifestParser.java
@@ -183,54 +183,61 @@ public class ManifestParser extends DefaultHandler {
}
/** {@inheritDoc} */
+ @SuppressWarnings("nls")
@Override
public void startElement(
String uri,
String localName,
String qName,
Attributes attributes) throws SAXException {
- if ("project".equals(qName)) { //$NON-NLS-1$
- if (attributes.getValue("name") == null) { //$NON-NLS-1$
+ if (qName == null) {
+ return;
+ }
+ switch (qName) {
+ case "project":
+ if (attributes.getValue("name") == null) {
throw new SAXException(RepoText.get().invalidManifest);
}
- currentProject = new RepoProject(
- attributes.getValue("name"), //$NON-NLS-1$
- attributes.getValue("path"), //$NON-NLS-1$
- attributes.getValue("revision"), //$NON-NLS-1$
- attributes.getValue("remote"), //$NON-NLS-1$
- attributes.getValue("groups")); //$NON-NLS-1$
- currentProject.setRecommendShallow(
- attributes.getValue("clone-depth")); //$NON-NLS-1$
- } else if ("remote".equals(qName)) { //$NON-NLS-1$
- String alias = attributes.getValue("alias"); //$NON-NLS-1$
- String fetch = attributes.getValue("fetch"); //$NON-NLS-1$
- String revision = attributes.getValue("revision"); //$NON-NLS-1$
+ currentProject = new RepoProject(attributes.getValue("name"),
+ attributes.getValue("path"),
+ attributes.getValue("revision"),
+ attributes.getValue("remote"),
+ attributes.getValue("groups"));
+ currentProject
+ .setRecommendShallow(attributes.getValue("clone-depth"));
+ break;
+ case "remote":
+ String alias = attributes.getValue("alias");
+ String fetch = attributes.getValue("fetch");
+ String revision = attributes.getValue("revision");
Remote remote = new Remote(fetch, revision);
- remotes.put(attributes.getValue("name"), remote); //$NON-NLS-1$
- if (alias != null)
+ remotes.put(attributes.getValue("name"), remote);
+ if (alias != null) {
remotes.put(alias, remote);
- } else if ("default".equals(qName)) { //$NON-NLS-1$
- defaultRemote = attributes.getValue("remote"); //$NON-NLS-1$
- defaultRevision = attributes.getValue("revision"); //$NON-NLS-1$
- } else if ("copyfile".equals(qName)) { //$NON-NLS-1$
- if (currentProject == null)
+ }
+ break;
+ case "default":
+ defaultRemote = attributes.getValue("remote");
+ defaultRevision = attributes.getValue("revision");
+ break;
+ case "copyfile":
+ if (currentProject == null) {
throw new SAXException(RepoText.get().invalidManifest);
- currentProject.addCopyFile(new CopyFile(
- rootRepo,
- currentProject.getPath(),
- attributes.getValue("src"), //$NON-NLS-1$
- attributes.getValue("dest"))); //$NON-NLS-1$
- } else if ("linkfile".equals(qName)) { //$NON-NLS-1$
+ }
+ currentProject.addCopyFile(new CopyFile(rootRepo,
+ currentProject.getPath(), attributes.getValue("src"),
+ attributes.getValue("dest")));
+ break;
+ case "linkfile":
if (currentProject == null) {
throw new SAXException(RepoText.get().invalidManifest);
}
- currentProject.addLinkFile(new LinkFile(
- rootRepo,
- currentProject.getPath(),
- attributes.getValue("src"), //$NON-NLS-1$
- attributes.getValue("dest"))); //$NON-NLS-1$
- } else if ("include".equals(qName)) { //$NON-NLS-1$
- String name = attributes.getValue("name"); //$NON-NLS-1$
+ currentProject.addLinkFile(new LinkFile(rootRepo,
+ currentProject.getPath(), attributes.getValue("src"),
+ attributes.getValue("dest")));
+ break;
+ case "include":
+ String name = attributes.getValue("name");
if (includedReader != null) {
try (InputStream is = includedReader.readIncludeFile(name)) {
if (is == null) {
@@ -239,8 +246,8 @@ public class ManifestParser extends DefaultHandler {
}
read(is);
} catch (Exception e) {
- throw new SAXException(MessageFormat.format(
- RepoText.get().errorIncludeFile, name), e);
+ throw new SAXException(MessageFormat
+ .format(RepoText.get().errorIncludeFile, name), e);
}
} else if (filename != null) {
int index = filename.lastIndexOf('/');
@@ -248,13 +255,18 @@ public class ManifestParser extends DefaultHandler {
try (InputStream is = new FileInputStream(path)) {
read(is);
} catch (IOException e) {
- throw new SAXException(MessageFormat.format(
- RepoText.get().errorIncludeFile, path), e);
+ throw new SAXException(MessageFormat
+ .format(RepoText.get().errorIncludeFile, path), e);
}
}
- } else if ("remove-project".equals(qName)) { //$NON-NLS-1$
- String name = attributes.getValue("name"); //$NON-NLS-1$
- projects.removeIf((p) -> p.getName().equals(name));
+ break;
+ case "remove-project": {
+ String name2 = attributes.getValue("name");
+ projects.removeIf((p) -> p.getName().equals(name2));
+ break;
+ }
+ default:
+ break;
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java
index 13f71a7ff6..d9059226a4 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/CommitBuilder.java
@@ -410,7 +410,8 @@ public class CommitBuilder {
throws IOException, IllegalArgumentException {
for (int i = 0; i < in.length(); ++i) {
char ch = in.charAt(i);
- if (ch == '\r') {
+ switch (ch) {
+ case '\r':
if (i + 1 < in.length() && in.charAt(i + 1) == '\n') {
out.write('\n');
out.write(' ');
@@ -419,15 +420,18 @@ public class CommitBuilder {
out.write('\n');
out.write(' ');
}
- } else if (ch == '\n') {
+ break;
+ case '\n':
out.write('\n');
out.write(' ');
- } else {
+ break;
+ default:
// sanity check
if (ch > 127)
throw new IllegalArgumentException(MessageFormat
.format(JGitText.get().notASCIIString, in));
out.write(ch);
+ break;
}
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommit.java b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommit.java
index 9914b0c991..a575dee029 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommit.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revplot/PlotCommit.java
@@ -102,27 +102,34 @@ public class PlotCommit<L extends PlotLane> extends RevCommit {
private static PlotLane[] addLane(PlotLane l, PlotLane[] lanes) {
final int cnt = lanes.length;
- if (cnt == 0)
+ switch (cnt) {
+ case 0:
lanes = new PlotLane[] { l };
- else if (cnt == 1)
+ break;
+ case 1:
lanes = new PlotLane[] { lanes[0], l };
- else {
+ break;
+ default:
final PlotLane[] n = new PlotLane[cnt + 1];
System.arraycopy(lanes, 0, n, 0, cnt);
n[cnt] = l;
lanes = n;
+ break;
}
return lanes;
}
void addChild(PlotCommit c) {
final int cnt = children.length;
- if (cnt == 0)
+ switch (cnt) {
+ case 0:
children = new PlotCommit[] { c };
- else if (cnt == 1) {
+ break;
+ case 1:
if (!c.getId().equals(children[0].getId()))
children = new PlotCommit[] { children[0], c };
- } else {
+ break;
+ default:
for (PlotCommit pc : children)
if (c.getId().equals(pc.getId()))
return;
@@ -130,6 +137,7 @@ public class PlotCommit<L extends PlotLane> extends RevCommit {
System.arraycopy(children, 0, n, 0, cnt);
n[cnt] = c;
children = n;
+ break;
}
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
index af4ec1f00b..98fb765699 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/revwalk/RevCommit.java
@@ -188,18 +188,22 @@ public class RevCommit extends RevObject {
}
idBuffer.fromString(raw, ptr + 7);
final RevCommit p = walk.lookupCommit(idBuffer);
- if (nParents == 0) {
+ switch (nParents) {
+ case 0:
pList[nParents++] = p;
- } else if (nParents == 1) {
+ break;
+ case 1:
pList = new RevCommit[] { pList[0], p };
nParents = 2;
- } else {
+ break;
+ default:
if (pList.length <= nParents) {
RevCommit[] old = pList;
pList = new RevCommit[pList.length + 32];
System.arraycopy(old, 0, pList, 0, nParents);
}
pList[nParents++] = p;
+ break;
}
ptr += 48;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AdvertiseRefsHookChain.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AdvertiseRefsHookChain.java
index 54c19783e3..1c670b73de 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/AdvertiseRefsHookChain.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/AdvertiseRefsHookChain.java
@@ -72,12 +72,14 @@ public class AdvertiseRefsHookChain implements AdvertiseRefsHook {
for (AdvertiseRefsHook hook : hooks)
if (hook != AdvertiseRefsHook.DEFAULT)
newHooks[i++] = hook;
- if (i == 0)
+ switch (i) {
+ case 0:
return AdvertiseRefsHook.DEFAULT;
- else if (i == 1)
+ case 1:
return newHooks[0];
- else
+ default:
return new AdvertiseRefsHookChain(newHooks, i);
+ }
}
/** {@inheritDoc} */
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java
index d73e1939a6..2af7f068dc 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PacketLineIn.java
@@ -148,12 +148,16 @@ public class PacketLineIn {
return AckNackResult.ACK;
final String arg = line.substring(44);
- if (arg.equals(" continue")) //$NON-NLS-1$
+ switch (arg) {
+ case " continue": //$NON-NLS-1$
return AckNackResult.ACK_CONTINUE;
- else if (arg.equals(" common")) //$NON-NLS-1$
+ case " common": //$NON-NLS-1$
return AckNackResult.ACK_COMMON;
- else if (arg.equals(" ready")) //$NON-NLS-1$
+ case " ready": //$NON-NLS-1$
return AckNackResult.ACK_READY;
+ default:
+ break;
+ }
}
if (line.startsWith("ERR ")) //$NON-NLS-1$
throw new PackProtocolException(line.substring(4));
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PostReceiveHookChain.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PostReceiveHookChain.java
index 0bdf7d4f6b..64598e1913 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PostReceiveHookChain.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PostReceiveHookChain.java
@@ -70,12 +70,14 @@ public class PostReceiveHookChain implements PostReceiveHook {
for (PostReceiveHook hook : hooks)
if (hook != PostReceiveHook.NULL)
newHooks[i++] = hook;
- if (i == 0)
+ switch (i) {
+ case 0:
return PostReceiveHook.NULL;
- else if (i == 1)
+ case 1:
return newHooks[0];
- else
+ default:
return new PostReceiveHookChain(newHooks, i);
+ }
}
/** {@inheritDoc} */
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PreReceiveHookChain.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PreReceiveHookChain.java
index 47b94c6e49..30594bdb6c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PreReceiveHookChain.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PreReceiveHookChain.java
@@ -69,12 +69,14 @@ public class PreReceiveHookChain implements PreReceiveHook {
for (PreReceiveHook hook : hooks)
if (hook != PreReceiveHook.NULL)
newHooks[i++] = hook;
- if (i == 0)
+ switch (i) {
+ case 0:
return PreReceiveHook.NULL;
- else if (i == 1)
+ case 1:
return newHooks[0];
- else
+ default:
return new PreReceiveHookChain(newHooks, i);
+ }
}
/** {@inheritDoc} */
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/GitDateParser.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/GitDateParser.java
index c6a6899948..1af11b241a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/GitDateParser.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/GitDateParser.java
@@ -252,12 +252,13 @@ public class GitDateParser {
}
// tries to parse a string with a relative time specification
+ @SuppressWarnings("nls")
private static Date parse_relative(String dateStr, Calendar now) {
Calendar cal;
SystemReader sysRead = SystemReader.getInstance();
// check for the static words "yesterday" or "now"
- if ("now".equals(dateStr)) { //$NON-NLS-1$
+ if ("now".equals(dateStr)) {
return ((now == null) ? new Date(sysRead.getCurrentTime()) : now
.getTime());
}
@@ -269,7 +270,7 @@ public class GitDateParser {
} else
cal = (Calendar) now.clone();
- if ("yesterday".equals(dateStr)) { //$NON-NLS-1$
+ if ("yesterday".equals(dateStr)) {
cal.add(Calendar.DATE, -1);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
@@ -280,12 +281,12 @@ public class GitDateParser {
}
// parse constructs like "3 days ago", "5.week.2.day.ago"
- String[] parts = dateStr.split("\\.| "); //$NON-NLS-1$
+ String[] parts = dateStr.split("\\.| ");
int partsLength = parts.length;
// check we have an odd number of parts (at least 3) and that the last
// part is "ago"
if (partsLength < 3 || (partsLength & 1) == 0
- || !"ago".equals(parts[parts.length - 1])) //$NON-NLS-1$
+ || !"ago".equals(parts[parts.length - 1]))
return null;
int number;
for (int i = 0; i < parts.length - 2; i += 2) {
@@ -294,27 +295,41 @@ public class GitDateParser {
} catch (NumberFormatException e) {
return null;
}
- if ("year".equals(parts[i + 1]) || "years".equals(parts[i + 1])) //$NON-NLS-1$ //$NON-NLS-2$
+ if (parts[i + 1] == null){
+ return null;
+ }
+ switch (parts[i + 1]) {
+ case "year":
+ case "years":
cal.add(Calendar.YEAR, -number);
- else if ("month".equals(parts[i + 1]) //$NON-NLS-1$
- || "months".equals(parts[i + 1])) //$NON-NLS-1$
+ break;
+ case "month":
+ case "months":
cal.add(Calendar.MONTH, -number);
- else if ("week".equals(parts[i + 1]) //$NON-NLS-1$
- || "weeks".equals(parts[i + 1])) //$NON-NLS-1$
+ break;
+ case "week":
+ case "weeks":
cal.add(Calendar.WEEK_OF_YEAR, -number);
- else if ("day".equals(parts[i + 1]) || "days".equals(parts[i + 1])) //$NON-NLS-1$ //$NON-NLS-2$
+ break;
+ case "day":
+ case "days":
cal.add(Calendar.DATE, -number);
- else if ("hour".equals(parts[i + 1]) //$NON-NLS-1$
- || "hours".equals(parts[i + 1])) //$NON-NLS-1$
+ break;
+ case "hour":
+ case "hours":
cal.add(Calendar.HOUR_OF_DAY, -number);
- else if ("minute".equals(parts[i + 1]) //$NON-NLS-1$
- || "minutes".equals(parts[i + 1])) //$NON-NLS-1$
+ break;
+ case "minute":
+ case "minutes":
cal.add(Calendar.MINUTE, -number);
- else if ("second".equals(parts[i + 1]) //$NON-NLS-1$
- || "seconds".equals(parts[i + 1])) //$NON-NLS-1$
+ break;
+ case "second":
+ case "seconds":
cal.add(Calendar.SECOND, -number);
- else
+ break;
+ default:
return null;
+ }
}
return cal.getTime();
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java
index f4b6f9d0df..7e8bbc80f8 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/StringUtils.java
@@ -322,16 +322,21 @@ public final class StringUtils {
int o = 0;
for (int i = 0; i < buf.length; ++i) {
char ch = in.charAt(i);
- if (ch == '\r') {
+ switch (ch) {
+ case '\r':
if (i + 1 < buf.length && in.charAt(i + 1) == '\n') {
buf[o++] = ' ';
++i;
} else
buf[o++] = ' ';
- } else if (ch == '\n')
+ break;
+ case '\n':
buf[o++] = ' ';
- else
+ break;
+ default:
buf[o++] = ch;
+ break;
+ }
}
return new String(buf, 0, o);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java
index d8cfee7c46..8eca6dce91 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java
@@ -129,9 +129,11 @@ public class AutoCRLFOutputStream extends OutputStream {
}
for (int i = off; i < off + len; ++i) {
final byte c = b[i];
- if (c == '\r') {
+ switch (c) {
+ case '\r':
buf = '\r';
- } else if (c == '\n') {
+ break;
+ case '\n':
if (buf != '\r') {
if (lastw < i) {
out.write(b, lastw, i - lastw);
@@ -140,8 +142,10 @@ public class AutoCRLFOutputStream extends OutputStream {
lastw = i;
}
buf = -1;
- } else {
+ break;
+ default:
buf = -1;
+ break;
}
}
if (lastw < off + len) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java
index 908d0a0b44..e235aa0ed4 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoLFOutputStream.java
@@ -138,14 +138,16 @@ public class AutoLFOutputStream extends OutputStream {
}
for (int i = off; i < off + len; ++i) {
final byte c = b[i];
- if (c == '\r') {
+ switch (c) {
+ case '\r':
// skip write r but backlog r
if (lastw < i) {
out.write(b, lastw, i - lastw);
}
lastw = i + 1;
buf = '\r';
- } else if (c == '\n') {
+ break;
+ case '\n':
if (buf == '\r') {
out.write('\n');
lastw = i + 1;
@@ -156,12 +158,14 @@ public class AutoLFOutputStream extends OutputStream {
}
lastw = i + 1;
}
- } else {
+ break;
+ default:
if (buf == '\r') {
out.write('\r');
lastw = i;
}
buf = -1;
+ break;
}
}
if (lastw < off + len) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/sha1/SHA1.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/sha1/SHA1.java
index 1ad6602fce..661b194209 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/sha1/SHA1.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/sha1/SHA1.java
@@ -325,11 +325,14 @@ public class SHA1 {
private void recompress(int t) {
State s;
- if (t == 58) {
+ switch (t) {
+ case 58:
s = state58;
- } else if (t == 65) {
+ break;
+ case 65:
s = state65;
- } else {
+ break;
+ default:
throw new IllegalStateException();
}
int a = s.a, b = s.b, c = s.c, d = s.d, e = s.e;

Back to the top