Simplify logic in GitDownloadCommand
Use fewer else conditions and rely on a single fall through return
null if it is not suitable to produce a command.
Change-Id: I70330af6bbab12d2be4ebe14cb4274d4af3bea01
diff --git a/src/main/java/com/googlesource/gerrit/plugins/download/command/GitDownloadCommand.java b/src/main/java/com/googlesource/gerrit/plugins/download/command/GitDownloadCommand.java
index eaeb82c..e7a3a04 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/download/command/GitDownloadCommand.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/download/command/GitDownloadCommand.java
@@ -38,22 +38,20 @@
@Override
public final String getCommand(DownloadScheme scheme, String project,
String ref) {
- if (!commandAllowed) {
- return null;
- }
-
- if (scheme instanceof SshScheme
- || scheme instanceof HttpScheme
- || scheme instanceof AnonymousHttpScheme
- || scheme instanceof GitScheme) {
+ if (commandAllowed && isRecognizedScheme(scheme)) {
String url = scheme.getUrl(project);
if (url != null) {
return getCommand(url, ref);
- } else
- return null;
- } else {
- return null;
+ }
}
+ return null;
+ }
+
+ private static boolean isRecognizedScheme(DownloadScheme scheme) {
+ return scheme instanceof SshScheme
+ || scheme instanceof HttpScheme
+ || scheme instanceof AnonymousHttpScheme
+ || scheme instanceof GitScheme;
}
abstract String getCommand(String url, String ref);