From 3497ff73331f692c5e7baa889efd0aae58749848 Mon Sep 17 00:00:00 2001 From: Mathis Chenuet Date: Wed, 28 Jan 2015 20:11:57 +0000 Subject: [PATCH] Cleanup: switch instead of ifs --- src/com/sheepit/client/Client.java | 80 ++++++++++--------- src/com/sheepit/client/standalone/Worker.java | 36 +++++---- 2 files changed, 60 insertions(+), 56 deletions(-) diff --git a/src/com/sheepit/client/Client.java b/src/com/sheepit/client/Client.java index c002711..9796ca8 100644 --- a/src/com/sheepit/client/Client.java +++ b/src/com/sheepit/client/Client.java @@ -537,46 +537,48 @@ public class Client { new_env.put("BLENDER_USER_CONFIG", this.config.workingDirectory.getAbsolutePath().replace("\\", "\\\\")); for (String arg : command1) { - if (arg.equals(".c")) { - command.add(ajob.getScenePath()); - command.add("-P"); - - try { - script_file = File.createTempFile("script_", "", this.config.workingDirectory); - File file = new File(script_file.getAbsolutePath()); - FileWriter txt; - txt = new FileWriter(file); + switch (arg) { + case ".c": + command.add(ajob.getScenePath()); + command.add("-P"); - PrintWriter out = new PrintWriter(txt); - out.write(ajob.getScript()); - out.write("\n"); - out.write(core_script); // GPU part - out.write("\n"); // GPU part - out.close(); - - command.add(script_file.getAbsolutePath()); - } - catch (IOException e) { - return Error.Type.UNKNOWN; - } - script_file.deleteOnExit(); - } - else if (arg.equals(".e")) { - command.add(ajob.getRendererPath()); - // the number of cores has to be put after the binary and before the scene arg - if (this.config.getNbCores() > 0) { - command.add("-t"); - command.add(Integer.toString(this.config.getNbCores())); - } - } - else if (arg.equals(".o")) { - command.add(this.config.workingDirectory.getAbsolutePath() + File.separator + ajob.getPrefixOutputImage()); - } - else if (arg.equals(".f")) { - command.add(ajob.getFrameNumber()); - } - else { - command.add(arg); + try { + script_file = File.createTempFile("script_", "", this.config.workingDirectory); + File file = new File(script_file.getAbsolutePath()); + FileWriter txt; + txt = new FileWriter(file); + + PrintWriter out = new PrintWriter(txt); + out.write(ajob.getScript()); + out.write("\n"); + out.write(core_script); // GPU part + out.write("\n"); // GPU part + out.close(); + + command.add(script_file.getAbsolutePath()); + } + catch (IOException e) { + return Error.Type.UNKNOWN; + } + script_file.deleteOnExit(); + break; + case ".e": + command.add(ajob.getRendererPath()); + // the number of cores has to be put after the binary and before the scene arg + if (this.config.getNbCores() > 0) { + command.add("-t"); + command.add(Integer.toString(this.config.getNbCores())); + } + break; + case ".o": + command.add(this.config.workingDirectory.getAbsolutePath() + File.separator + ajob.getPrefixOutputImage()); + break; + case ".f": + command.add(ajob.getFrameNumber()); + break; + default: + command.add(arg); + break; } } diff --git a/src/com/sheepit/client/standalone/Worker.java b/src/com/sheepit/client/standalone/Worker.java index ca45b3a..bded511 100644 --- a/src/com/sheepit/client/standalone/Worker.java +++ b/src/com/sheepit/client/standalone/Worker.java @@ -266,23 +266,25 @@ public class Worker { Log.getInstance(config).debug("client version " + config.getJarVersion()); Gui gui; - if (ui_type.equals("oneline")) { - if (config.getPrintLog()) { - System.out.println("OneLine UI can not be used if verbose mode is enabled"); - System.exit(2); - } - gui = new GuiTextOneLine(); - } - else if (ui_type.equals("swing")) { - if (java.awt.GraphicsEnvironment.isHeadless()) { - 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.exit(3); - } - gui = new GuiSwing(); - } - else { - gui = new GuiText(); + switch (ui_type) { + case "oneline": + if (config.getPrintLog()) { + System.out.println("OneLine UI can not be used if verbose mode is enabled"); + System.exit(2); + } + gui = new GuiTextOneLine(); + break; + case "swing": + if (java.awt.GraphicsEnvironment.isHeadless()) { + 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.exit(3); + } + gui = new GuiSwing(); + break; + default: + gui = new GuiText(); + break; } Client cli = new Client(gui, config, server); gui.setClient(cli);