@Test(expected = PreconditionException.class) public void testBadCondition() throws Exception { Row row = new Row("a", 1).add("b", "x").add("c", 2.06); Assert.assertEquals(true, new Precondition("c").apply(row)); }
public boolean apply(Row row) throws PreconditionException { Bindings ctx = new SimpleBindings(); for (int i = 0; i < row.width(); ++i) { ctx.put(row.getColumn(i), row.getValue(i)); } try { Object result = script.eval(ctx); if (!(result instanceof Boolean)) { throw new PreconditionException( String.format("Precondition '%s' does not result in true or false.", condition) ); } return (Boolean) result; } catch (ScriptException e) { if (e.getCause() != null) { throw new PreconditionException(e.getCause().getMessage()); } else { throw new PreconditionException(e.getMessage()); } } }
Precondition { public boolean apply(Row row) throws PreconditionException { Bindings ctx = new SimpleBindings(); for (int i = 0; i < row.width(); ++i) { ctx.put(row.getColumn(i), row.getValue(i)); } try { Object result = script.eval(ctx); if (!(result instanceof Boolean)) { throw new PreconditionException( String.format("Precondition '%s' does not result in true or false.", condition) ); } return (Boolean) result; } catch (ScriptException e) { if (e.getCause() != null) { throw new PreconditionException(e.getCause().getMessage()); } else { throw new PreconditionException(e.getMessage()); } } } }
Precondition { public boolean apply(Row row) throws PreconditionException { Bindings ctx = new SimpleBindings(); for (int i = 0; i < row.width(); ++i) { ctx.put(row.getColumn(i), row.getValue(i)); } try { Object result = script.eval(ctx); if (!(result instanceof Boolean)) { throw new PreconditionException( String.format("Precondition '%s' does not result in true or false.", condition) ); } return (Boolean) result; } catch (ScriptException e) { if (e.getCause() != null) { throw new PreconditionException(e.getCause().getMessage()); } else { throw new PreconditionException(e.getMessage()); } } } Precondition(String condition); }
Precondition { public boolean apply(Row row) throws PreconditionException { Bindings ctx = new SimpleBindings(); for (int i = 0; i < row.width(); ++i) { ctx.put(row.getColumn(i), row.getValue(i)); } try { Object result = script.eval(ctx); if (!(result instanceof Boolean)) { throw new PreconditionException( String.format("Precondition '%s' does not result in true or false.", condition) ); } return (Boolean) result; } catch (ScriptException e) { if (e.getCause() != null) { throw new PreconditionException(e.getCause().getMessage()); } else { throw new PreconditionException(e.getMessage()); } } } Precondition(String condition); boolean apply(Row row); }
Precondition { public boolean apply(Row row) throws PreconditionException { Bindings ctx = new SimpleBindings(); for (int i = 0; i < row.width(); ++i) { ctx.put(row.getColumn(i), row.getValue(i)); } try { Object result = script.eval(ctx); if (!(result instanceof Boolean)) { throw new PreconditionException( String.format("Precondition '%s' does not result in true or false.", condition) ); } return (Boolean) result; } catch (ScriptException e) { if (e.getCause() != null) { throw new PreconditionException(e.getCause().getMessage()); } else { throw new PreconditionException(e.getMessage()); } } } Precondition(String condition); boolean apply(Row row);  }