/** * Tries to convert a node to an integer * * @param n * Node * @return Integer * @throws SQLException * Thrown if the node cannot be converted */ public static int toInt(Node n) throws SQLException { try { if (n == null) return 0; if (n.isLiteral()) { return NodeFactoryExtra.nodeToInt(n); } else { throw new SQLException("Unable to marshal a non-literal to an integer"); } } catch (SQLException e) { // Throw as is throw e; } catch (Exception e) { // Wrap other exceptions throw new SQLException("Unable to marshal the value to an integer", e); } }
/** * Tries to convert a node to an integer * * @param n * Node * @return Integer * @throws SQLException * Thrown if the node cannot be converted */ public static int toInt(Node n) throws SQLException { try { if (n == null) return 0; if (n.isLiteral()) { return NodeFactoryExtra.nodeToInt(n); } else { throw new SQLException("Unable to marshal a non-literal to an integer"); } } catch (SQLException e) { // Throw as is throw e; } catch (Exception e) { // Wrap other exceptions throw new SQLException("Unable to marshal the value to an integer", e); } }
private QueryIterator verify(Binding binding, Graph graph, Node listNode, Node length, ExecutionContext execCxt) { int x = GraphList.length(new GNode(graph, listNode)) ; int len = NodeFactoryExtra.nodeToInt(length) ; if ( x == len ) return IterLib.result(binding, execCxt) ; return IterLib.noResults(execCxt) ; }
int v = NodeFactoryExtra.nodeToInt(x); limit = (v < 0) ? -1 : v;
private static QueryIterator getByIndex(Graph graph, Binding binding, Node listNode, Node indexNode, Var varMember, ExecutionContext execCxt) { int i = NodeFactoryExtra.nodeToInt(indexNode) ; if ( i < 0 ) return IterLib.noResults(execCxt) ; Node n = GraphList.get(new GNode(graph, listNode), i) ; if ( n == null ) return IterLib.noResults(execCxt) ; return IterLib.oneResult(binding, varMember, n, execCxt) ; }
int v = NodeFactoryExtra.nodeToInt(x); limit = (v < 0) ? -1 : v;
int v = NodeFactoryExtra.nodeToInt(x); limit = (v < 0) ? -1 : v;
int v = NodeFactoryExtra.nodeToInt(x); limit = (v < 0) ? -1 : v;
int v = NodeFactoryExtra.nodeToInt(x); limit = (v < 0) ? -1 : v;
int v = NodeFactoryExtra.nodeToInt(x); limit = (v < 0) ? -1 : v;
int v = NodeFactoryExtra.nodeToInt(x) ; limit = (v < 0) ? -1 : v ;
private static QueryIterator testSlotValue(Graph graph, Binding binding, Node listNode, Node indexNode, Node memberNode, ExecutionContext execCxt) { int i = NodeFactoryExtra.nodeToInt(indexNode) ; if ( i < 0 ) return IterLib.noResults(execCxt) ; Node n = GraphList.get(new GNode(graph, listNode), i) ; if ( n == null ) return IterLib.noResults(execCxt) ; if ( n.equals(memberNode) ) return IterLib.result(binding, execCxt) ; else return IterLib.noResults(execCxt) ; }
int v = NodeFactoryExtra.nodeToInt(x) ; limit = (v < 0) ? -1 : v ;
@Test public void test_function_non_expansion_02() { Expr square = new E_Multiply(new ExprVar("x"), new ExprVar("x")); UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<>(square.getVarsMentioned())); //This test illustrates that if we change the definition of square and call our function again we can //get a different result with dependencies preserved because the definition of the dependent function can change Expr cube = new E_Multiply(new E_Function("http://example/square", new ExprList(new ExprVar("x"))), new ExprVar("x")); UserDefinedFunctionFactory.getFactory().add("http://example/cube", cube, new ArrayList<>(cube.getVarsMentioned())); UserDefinedFunction f = (UserDefinedFunction) UserDefinedFunctionFactory.getFactory().create("http://example/cube"); f.build("http://example/cube", new ExprList(new NodeValueInteger(2))); Expr actual = f.getActualExpr(); NodeValue result = actual.eval(BindingFactory.create(), LibTestExpr.createTest()); Assert.assertEquals(8, NodeFactoryExtra.nodeToInt(result.asNode())); //Change the definition of the function we depend on square = new ExprVar("x"); UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<>(square.getVarsMentioned())); f.build("http://example/cube", new ExprList(new NodeValueInteger(2))); actual = f.getActualExpr(); result = actual.eval(BindingFactory.create(), LibTestExpr.createTest()); Assert.assertEquals(4, NodeFactoryExtra.nodeToInt(result.asNode())); } }
@Test public void test_function_expansion_13() { Expr square = new E_Multiply(new ExprVar("x"), new ExprVar("x")); UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<>(square.getVarsMentioned())); //This test illustrates that if we change the definition of square and call our function again we always //get the same result with dependencies not preserved because even though the definition of the dependent function //can change the definition of our function is fully expanded when first defined Expr cube = new E_Multiply(new E_Function("http://example/square", new ExprList(new ExprVar("x"))), new ExprVar("x")); UserDefinedFunctionFactory.getFactory().add("http://example/cube", cube, new ArrayList<>(cube.getVarsMentioned())); UserDefinedFunction f = (UserDefinedFunction) UserDefinedFunctionFactory.getFactory().create("http://example/cube"); f.build("http://example/cube", new ExprList(new NodeValueInteger(2))); Expr actual = f.getActualExpr(); NodeValue result = actual.eval(BindingFactory.create(), LibTestExpr.createTest()); Assert.assertEquals(8, NodeFactoryExtra.nodeToInt(result.asNode())); //Change the definition of the function we depend on //This has no effect with preserveDependencies set to false (the default) since we fully expanded the call to the dependent //function when our outer function was defined square = new ExprVar("x"); UserDefinedFunctionFactory.getFactory().add("http://example/square", square, new ArrayList<>(square.getVarsMentioned())); f.build("http://example/cube", new ExprList(new NodeValueInteger(2))); actual = f.getActualExpr(); result = actual.eval(BindingFactory.create(), LibTestExpr.createTest()); Assert.assertEquals(8, NodeFactoryExtra.nodeToInt(result.asNode())); }