@Test public void test6() { String input = "!0 * 0 + 1"; ParseBoolean tester = new ParseBoolean(input); int testResults = tester.parse(); assertEquals("Result",1, testResults ); }
public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse(); }
ParseBoolean { public int parse() { String expression = " if(" + _input + "){" + "returnValue = VALUEA;" + "}" + " else { returnValue = VALUEB; }"; expression = expression.replaceAll("0", " false " ); expression = expression.replaceAll("1", " true " ); expression = expression.replaceAll("\\*", " && " ); expression = expression.replaceAll("\\+", " || " ); expression = expression.replace("VALUEA", " \"1\" " ); expression = expression.replace("VALUEB", " \"0\" " ); System.out.println(expression); ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("js"); Object result = null; try { result = engine.eval(expression); } catch (ScriptException e) { } return result == null ? 0 :Integer.parseInt(result.toString()); } ParseBoolean(String input); int parse();  }