ZeroLengthPathIteration extends LookAheadIteration<BindingSet, QueryEvaluationException> { @Override protected BindingSet getNextElement() throws QueryEvaluationException { if (subj == null && obj == null) { if (this.reportedValues == null) { reportedValues = makeSet(); } if (this.iter == null) { QueryBindingSet bs1 = new QueryBindingSet(1); bs1.addBinding(ANON_SEQUENCE_VAR, ValueFactoryImpl.getInstance().createLiteral("subject")); QueryBindingSet bs2 = new QueryBindingSet(1); bs2.addBinding(ANON_SEQUENCE_VAR, ValueFactoryImpl.getInstance().createLiteral("object")); List<BindingSet> seqList = Arrays.<BindingSet>asList(bs1, bs2); iter = new CrossProductIteration(createIteration(), seqList); } while (iter.hasNext()) { BindingSet bs = iter.next(); boolean isSubjOrObj = bs.getValue(ANON_SEQUENCE_VAR).stringValue().equals("subject"); String endpointVarName = isSubjOrObj ? ANON_SUBJECT_VAR : ANON_OBJECT_VAR; Value v = bs.getValue(endpointVarName); if (add(reportedValues, v)) { QueryBindingSet next = new QueryBindingSet(bindings); next.addBinding(subjectVar.getName(), v); next.addBinding(objVar.getName(), v); if (contextVar != null) { Value context = bs.getValue(contextVar.getName()); if (context != null) { next.addBinding(contextVar.getName(), context); } } return next; } } iter.close(); reportedValues = null; return null; } else { if (result != null) { if (obj == null && subj != null) { result.addBinding(objVar.getName(), subj); } else if (subj == null && obj != null) { result.addBinding(subjectVar.getName(), obj); } else if (subj != null && subj.equals(obj)) { } else { result = null; } } QueryBindingSet next = result; result = null; return next; } } ZeroLengthPathIteration(EvaluationStrategy evaluationStrategyImpl, Var subjectVar, Var objVar, Value subj,
			Value obj, Var contextVar, BindingSet bindings); Var createAnonVar(String varName);  }
@Test public void testRetainInputBindings() { MapBindingSet bindings = new MapBindingSet(); bindings.addBinding("a", RDF.FIRST); Var subjectVar = new Var("x"); Var objVar = new Var("y"); try (ZeroLengthPathIteration zlp = new ZeroLengthPathIteration(evaluator, subjectVar, objVar, null, null, null, bindings)) { BindingSet result = zlp.getNextElement(); assertTrue("zlp evaluation should have retained unrelated input binding", result.hasBinding("a")); assertTrue("zlp evaluation should binding for subject var", result.hasBinding("x")); assertTrue("zlp evaluation should binding for object var", result.hasBinding("y")); } }