Cleanup: switch instead of ifs

This commit is contained in:
Mathis Chenuet
2015-01-28 20:11:57 +00:00
committed by Laurent Clouet
parent bda6691159
commit 3497ff7333
2 changed files with 60 additions and 56 deletions

View File

@@ -537,7 +537,8 @@ public class Client {
new_env.put("BLENDER_USER_CONFIG", this.config.workingDirectory.getAbsolutePath().replace("\\", "\\\\")); new_env.put("BLENDER_USER_CONFIG", this.config.workingDirectory.getAbsolutePath().replace("\\", "\\\\"));
for (String arg : command1) { for (String arg : command1) {
if (arg.equals(".c")) { switch (arg) {
case ".c":
command.add(ajob.getScenePath()); command.add(ajob.getScenePath());
command.add("-P"); command.add("-P");
@@ -560,23 +561,24 @@ public class Client {
return Error.Type.UNKNOWN; return Error.Type.UNKNOWN;
} }
script_file.deleteOnExit(); script_file.deleteOnExit();
} break;
else if (arg.equals(".e")) { case ".e":
command.add(ajob.getRendererPath()); command.add(ajob.getRendererPath());
// the number of cores has to be put after the binary and before the scene arg // the number of cores has to be put after the binary and before the scene arg
if (this.config.getNbCores() > 0) { if (this.config.getNbCores() > 0) {
command.add("-t"); command.add("-t");
command.add(Integer.toString(this.config.getNbCores())); command.add(Integer.toString(this.config.getNbCores()));
} }
} break;
else if (arg.equals(".o")) { case ".o":
command.add(this.config.workingDirectory.getAbsolutePath() + File.separator + ajob.getPrefixOutputImage()); command.add(this.config.workingDirectory.getAbsolutePath() + File.separator + ajob.getPrefixOutputImage());
} break;
else if (arg.equals(".f")) { case ".f":
command.add(ajob.getFrameNumber()); command.add(ajob.getFrameNumber());
} break;
else { default:
command.add(arg); command.add(arg);
break;
} }
} }

View File

@@ -266,23 +266,25 @@ public class Worker {
Log.getInstance(config).debug("client version " + config.getJarVersion()); Log.getInstance(config).debug("client version " + config.getJarVersion());
Gui gui; Gui gui;
if (ui_type.equals("oneline")) { switch (ui_type) {
case "oneline":
if (config.getPrintLog()) { if (config.getPrintLog()) {
System.out.println("OneLine UI can not be used if verbose mode is enabled"); System.out.println("OneLine UI can not be used if verbose mode is enabled");
System.exit(2); System.exit(2);
} }
gui = new GuiTextOneLine(); gui = new GuiTextOneLine();
} break;
else if (ui_type.equals("swing")) { case "swing":
if (java.awt.GraphicsEnvironment.isHeadless()) { if (java.awt.GraphicsEnvironment.isHeadless()) {
System.out.println("Graphical ui can not be launch."); System.out.println("Graphical ui can not be launch.");
System.out.println("You should set a DISPLAY or use a text ui (via -ui oneline or -ui text)."); System.out.println("You should set a DISPLAY or use a text ui (via -ui oneline or -ui text).");
System.exit(3); System.exit(3);
} }
gui = new GuiSwing(); gui = new GuiSwing();
} break;
else { default:
gui = new GuiText(); gui = new GuiText();
break;
} }
Client cli = new Client(gui, config, server); Client cli = new Client(gui, config, server);
gui.setClient(cli); gui.setClient(cli);