@Test public void testTwoNodeOrder() { SPARQLParser parser = new SPARQLParser(); ParsedQuery pq1 = null; ParsedQuery pq2 = null; try { pq1 = parser.parseQuery(q7, null); pq2 = parser.parseQuery(q8, null); } catch (MalformedQueryException e) { e.printStackTrace(); } Set<TupleExpr> tupSet = Sets.newHashSet(); tupSet.add(pq1.getTupleExpr()); TupleExecutionPlanGenerator tep = new TupleExecutionPlanGenerator(); Iterator<TupleExpr> processedTups = tep.getPlans(tupSet.iterator()); List<TupleExpr> processedTupList = Lists.newArrayList(); int size = 0; while(processedTups.hasNext()) { Assert.assertTrue(processedTups.hasNext()); processedTupList.add(processedTups.next()); size++; } Assert.assertEquals(2, size); Assert.assertEquals(pq1.getTupleExpr(), processedTupList.get(0)); Assert.assertEquals(pq2.getTupleExpr(), processedTupList.get(1)); }
@Override public Iterator<TupleExpr> getPlans(final Iterator<TupleExpr> indexPlans) { final Iterator<TupleExpr> iter = indexPlans; return new Iterator<TupleExpr>() { private TupleExpr next = null; private boolean hasNextCalled = false; private boolean isEmpty = false; Iterator<TupleExpr> tuples = null; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (tuples != null && tuples.hasNext()) { next = tuples.next(); hasNextCalled = true; return true; } else { while (iter.hasNext()) { tuples = getPlans(iter.next()).iterator(); if (tuples == null) { throw new IllegalStateException("Plans cannot be null!"); } next = tuples.next(); hasNextCalled = true; return true; } isEmpty = true; return false; } } else { return !isEmpty; } } @Override public TupleExpr next() { if (hasNextCalled) { hasNextCalled = false; return next; } else if(isEmpty) { throw new NoSuchElementException(); }else { if (this.hasNext()) { hasNextCalled = false; return next; } else { throw new NoSuchElementException(); } } } @Override public void remove() { throw new UnsupportedOperationException("Cannot delete from iterator!"); } }; }
TupleExecutionPlanGenerator implements IndexTupleGenerator { @Override public Iterator<TupleExpr> getPlans(final Iterator<TupleExpr> indexPlans) { final Iterator<TupleExpr> iter = indexPlans; return new Iterator<TupleExpr>() { private TupleExpr next = null; private boolean hasNextCalled = false; private boolean isEmpty = false; Iterator<TupleExpr> tuples = null; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (tuples != null && tuples.hasNext()) { next = tuples.next(); hasNextCalled = true; return true; } else { while (iter.hasNext()) { tuples = getPlans(iter.next()).iterator(); if (tuples == null) { throw new IllegalStateException("Plans cannot be null!"); } next = tuples.next(); hasNextCalled = true; return true; } isEmpty = true; return false; } } else { return !isEmpty; } } @Override public TupleExpr next() { if (hasNextCalled) { hasNextCalled = false; return next; } else if(isEmpty) { throw new NoSuchElementException(); }else { if (this.hasNext()) { hasNextCalled = false; return next; } else { throw new NoSuchElementException(); } } } @Override public void remove() { throw new UnsupportedOperationException("Cannot delete from iterator!"); } }; } }
TupleExecutionPlanGenerator implements IndexTupleGenerator { @Override public Iterator<TupleExpr> getPlans(final Iterator<TupleExpr> indexPlans) { final Iterator<TupleExpr> iter = indexPlans; return new Iterator<TupleExpr>() { private TupleExpr next = null; private boolean hasNextCalled = false; private boolean isEmpty = false; Iterator<TupleExpr> tuples = null; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (tuples != null && tuples.hasNext()) { next = tuples.next(); hasNextCalled = true; return true; } else { while (iter.hasNext()) { tuples = getPlans(iter.next()).iterator(); if (tuples == null) { throw new IllegalStateException("Plans cannot be null!"); } next = tuples.next(); hasNextCalled = true; return true; } isEmpty = true; return false; } } else { return !isEmpty; } } @Override public TupleExpr next() { if (hasNextCalled) { hasNextCalled = false; return next; } else if(isEmpty) { throw new NoSuchElementException(); }else { if (this.hasNext()) { hasNextCalled = false; return next; } else { throw new NoSuchElementException(); } } } @Override public void remove() { throw new UnsupportedOperationException("Cannot delete from iterator!"); } }; }  }
TupleExecutionPlanGenerator implements IndexTupleGenerator { @Override public Iterator<TupleExpr> getPlans(final Iterator<TupleExpr> indexPlans) { final Iterator<TupleExpr> iter = indexPlans; return new Iterator<TupleExpr>() { private TupleExpr next = null; private boolean hasNextCalled = false; private boolean isEmpty = false; Iterator<TupleExpr> tuples = null; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (tuples != null && tuples.hasNext()) { next = tuples.next(); hasNextCalled = true; return true; } else { while (iter.hasNext()) { tuples = getPlans(iter.next()).iterator(); if (tuples == null) { throw new IllegalStateException("Plans cannot be null!"); } next = tuples.next(); hasNextCalled = true; return true; } isEmpty = true; return false; } } else { return !isEmpty; } } @Override public TupleExpr next() { if (hasNextCalled) { hasNextCalled = false; return next; } else if(isEmpty) { throw new NoSuchElementException(); }else { if (this.hasNext()) { hasNextCalled = false; return next; } else { throw new NoSuchElementException(); } } } @Override public void remove() { throw new UnsupportedOperationException("Cannot delete from iterator!"); } }; }  @Override Iterator<TupleExpr> getPlans(final Iterator<TupleExpr> indexPlans); }
TupleExecutionPlanGenerator implements IndexTupleGenerator { @Override public Iterator<TupleExpr> getPlans(final Iterator<TupleExpr> indexPlans) { final Iterator<TupleExpr> iter = indexPlans; return new Iterator<TupleExpr>() { private TupleExpr next = null; private boolean hasNextCalled = false; private boolean isEmpty = false; Iterator<TupleExpr> tuples = null; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (tuples != null && tuples.hasNext()) { next = tuples.next(); hasNextCalled = true; return true; } else { while (iter.hasNext()) { tuples = getPlans(iter.next()).iterator(); if (tuples == null) { throw new IllegalStateException("Plans cannot be null!"); } next = tuples.next(); hasNextCalled = true; return true; } isEmpty = true; return false; } } else { return !isEmpty; } } @Override public TupleExpr next() { if (hasNextCalled) { hasNextCalled = false; return next; } else if(isEmpty) { throw new NoSuchElementException(); }else { if (this.hasNext()) { hasNextCalled = false; return next; } else { throw new NoSuchElementException(); } } } @Override public void remove() { throw new UnsupportedOperationException("Cannot delete from iterator!"); } }; }  @Override Iterator<TupleExpr> getPlans(final Iterator<TupleExpr> indexPlans);  }