ValuesHandler implements Handler { public ElementData asElement() { ElementData ed = new ElementData(); List<Var> vars = new ArrayList<Var>(valuesTable.keySet()); vars.removeAll(valueMap.keySet()); if (vars.isEmpty()) { return ed; } vars.forEach( var -> ed.add(var)); int count = valuesTable.get(vars.get(0)).size(); for (int i = 0; i < count; i++) { BindingHashMap b = new BindingHashMap(); for (Var var : vars) { List<Node> lst = valuesTable.get(var); if (lst.size() != count) { throw new QueryBuildException( String.format("The number of data items for %s (%s) is not the same as for %s (%s)", var, lst.size(), vars.get(0), count)); } Node n = lst.get(i); if (n != null) { if (valueMap.containsKey(n)) { n = valueMap.get(n); } b.add(var, n); } } if (!b.isEmpty()) { ed.add(b); } } return ed; } ValuesHandler();  ValuesHandler( Query query ); ElementData asElement(); boolean isEmpty(); @Override void setVars(Map<Var, Node> values); @Override void build(); void addValueVar(Var var, Collection<Node> nodes); void addValueRow(Collection<Node> values); void addAll(ValuesHandler handler); void clear(); List<Var> getValuesVars(); Map<Var,List<Node>> getValuesMap();  }
@Test public void testAsElement() { final Var v = Var.alloc("v"); final Var x = Var.alloc("x"); final Node one = NodeFactory.createURI( "one"); final Node two = NodeFactory.createURI( "two"); final Node three = NodeFactory.createLiteral( "three"); final Node four = NodeFactory.createLiteral( "four"); handler.addValueVar( v, Arrays.asList( one, two )); handler.addValueVar( x, Arrays.asList( three, four )); ElementData edat = new ElementData(); edat.add( v ); edat.add( x ); BindingHashMap binding = new BindingHashMap(); binding.add( v, NodeFactory.createURI( "one" )); binding.add( x, NodeFactory.createLiteral("three")); edat.add( binding ); binding = new BindingHashMap(); binding.add( v, NodeFactory.createURI( "two" )); binding.add( x, NodeFactory.createLiteral("four")); edat.add( binding ); WhereValidator visitor = new WhereValidator( edat ); handler.asElement().visit( visitor ); assertTrue( visitor.matching ); }