use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class ResultSetPeeking method nextBinding.
@Override
public Binding nextBinding() {
if (this.hasPeeked()) {
Binding b = this.peeked;
this.peeked = null;
this.rowNumber++;
return b;
} else if (this.canPeek()) {
Binding b = this.peekBinding();
this.peeked = null;
this.rowNumber++;
return b;
} else {
throw new NoSuchElementException();
}
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class TestResultSet method test_RS_peeking_9.
@Test
public void test_RS_peeking_9() {
// Check that peeking causes the correct row to be returned when we actually access the rows
Node first = NodeFactory.createURI("tag:first");
Node second = NodeFactory.createURI("tag:second");
Var x = Var.alloc("x");
ResultSet inner = new ResultSetMem(make("x", first), make("x", second));
ResultSetPeekable rs = ResultSetFactory.makePeekable(inner);
assertTrue(rs.hasNext());
// Peek and check row is as expected
Binding peeked = rs.peekBinding();
assertNotNull(peeked);
assertTrue(first.equals(peeked.get(x)));
// Check first row is as expected
Binding next = rs.nextBinding();
assertNotNull(next);
assertTrue(first.equals(next.get(x)));
// Repeat for second row
peeked = rs.peekBinding();
assertNotNull(peeked);
assertTrue(second.equals(peeked.get(x)));
next = rs.nextBinding();
assertNotNull(next);
assertTrue(second.equals(next.get(x)));
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class TestResultSet method make2.
private ResultSet make2(String var, Node val) {
BindingMap b1 = BindingFactory.create();
b1.add(Var.alloc(var), val);
BindingMap b2 = BindingFactory.create();
b2.add(Var.alloc(var), val);
List<String> vars = new ArrayList<>();
vars.add(var);
List<Binding> solutions = new ArrayList<>();
solutions.add(b1);
solutions.add(b2);
QueryIterator qIter = new QueryIterPlainWrapper(solutions.iterator(), null);
ResultSet rs = new ResultSetStream(vars, null, qIter);
return rs;
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class ValuesHandlerTest method twoVarTwoBlocksReplaceDataVar.
@Test
public void twoVarTwoBlocksReplaceDataVar() {
Node n = NodeFactory.createLiteral("hello");
Node nn = NodeFactory.createLiteral("hola");
Node n2 = NodeFactory.createLiteral("there");
Var nn2 = Var.alloc("z");
Var v = Var.alloc("x");
Var v2 = Var.alloc("y");
handler.addValueVar(v, null);
handler.addValueVar(v2, null);
handler.addValueRow(Arrays.asList(n, n2));
handler.addValueRow(Arrays.asList(nn, nn2));
Node rep = NodeFactory.createLiteral("aqui");
Map<Var, Node> replaceVars = new HashMap<Var, Node>();
replaceVars.put(nn2, rep);
handler.setVars(replaceVars);
handler.build();
List<Var> vars = query.getValuesVariables();
assertEquals(2, vars.size());
assertTrue(vars.contains(v));
assertTrue(vars.contains(v2));
assertNotNull(query.getValuesData());
List<Binding> lb = query.getValuesData();
assertEquals(2, lb.size());
List<Node> ln = new ArrayList<Node>();
ln.add(n);
ln.add(nn);
List<Node> ln2 = new ArrayList<Node>();
ln2.add(n2);
ln2.add(rep);
for (Binding b : lb) {
assertTrue(b.contains(v));
assertTrue(ln.contains(b.get(v)));
ln.remove(b.get(v));
assertTrue(b.contains(v2));
assertTrue(ln2.contains(b.get(v2)));
ln2.remove(b.get(v2));
}
}
use of org.apache.jena.sparql.engine.binding.Binding in project jena by apache.
the class ValuesHandlerTest method testAddSquare.
@Test
public void testAddSquare() {
Node n = NodeFactory.createLiteral("hello");
Node nn = NodeFactory.createLiteral("hola");
Node n2 = NodeFactory.createLiteral("there");
Node nn2 = NodeFactory.createLiteral("aqui");
Var v = Var.alloc("x");
Var v2 = Var.alloc("y");
handler.addValueVar(v, Arrays.asList(n, n2));
handler.addValueVar(v2, Arrays.asList(nn, nn2));
ValuesHandler handler2 = new ValuesHandler(new Query());
Node n3 = NodeFactory.createLiteral("why");
Node nn3 = NodeFactory.createLiteral("quando");
handler2.addValueVar(v, Arrays.asList(n3));
handler2.addValueVar(v2, Arrays.asList(nn3));
handler.addAll(handler2);
handler.build();
List<Var> vars = query.getValuesVariables();
assertEquals(2, vars.size());
assertTrue(vars.contains(v));
assertTrue(vars.contains(v2));
assertNotNull(query.getValuesData());
List<Binding> lb = query.getValuesData();
assertEquals(3, lb.size());
List<Node> ln = new ArrayList<Node>();
ln.add(n);
ln.add(n2);
ln.add(n3);
List<Node> ln2 = new ArrayList<Node>();
ln2.add(nn);
ln2.add(nn2);
ln2.add(nn3);
for (Binding b : lb) {
assertTrue(b.contains(v));
assertTrue(ln.contains(b.get(v)));
ln.remove(b.get(v));
assertTrue(b.contains(v2));
assertTrue(ln2.contains(b.get(v2)));
ln2.remove(b.get(v2));
}
}
Aggregations