@Test public void singleIndex() { String q1 = "" + "SELECT ?f ?m ?d " + "{" + " ?f a ?m ." + " ?m <http: + " ?d <uri:talksTo> ?f . " + " ?f <uri:hangOutWith> ?m ." + " ?m <uri:hangOutWith> ?d ." + " ?f <uri:associatesWith> ?m ." + " ?m <uri:associatesWith> ?d ." + "}"; SPARQLParser parser = new SPARQLParser(); ParsedQuery pq1 = null; SimpleExternalTupleSet extTup1 = null; try { pq1 = parser.parseQuery(q1, null); extTup1 = new SimpleExternalTupleSet( (Projection) pq1.getTupleExpr()); } catch (MalformedQueryException e) { e.printStackTrace(); } List<ExternalTupleSet> indexList = Lists.newArrayList(); indexList.add(extTup1); ValidIndexCombinationGenerator vic = new ValidIndexCombinationGenerator( pq1.getTupleExpr()); Iterator<List<ExternalTupleSet>> combos = vic .getValidIndexCombos(indexList); int size = 0; while (combos.hasNext()) { combos.hasNext(); size++; combos.next(); combos.hasNext(); } Assert.assertTrue(!combos.hasNext()); Assert.assertEquals(1, size); }
public Iterator<List<ExternalTupleSet>> getValidIndexCombos( List<ExternalTupleSet> indexSet) { Collections.shuffle(indexSet); final List<ExternalTupleSet> list = indexSet; final Iterator<List<Integer>> iter = getValidCombos(list); return new Iterator<List<ExternalTupleSet>>() { private List<ExternalTupleSet> next = null; private List<Integer> nextCombo = null; private boolean hasNextCalled = false; private boolean isEmpty = false; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (!iter.hasNext()) { isEmpty = true; return false; } else { nextCombo = iter.next(); List<ExternalTupleSet> indexCombo = Lists .newArrayList(); for (Integer i : nextCombo) { indexCombo.add(list.get(i)); } next = indexCombo; hasNextCalled = true; return true; } } else { return !isEmpty; } } @Override public List<ExternalTupleSet> 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!"); } }; }
ValidIndexCombinationGenerator { public Iterator<List<ExternalTupleSet>> getValidIndexCombos( List<ExternalTupleSet> indexSet) { Collections.shuffle(indexSet); final List<ExternalTupleSet> list = indexSet; final Iterator<List<Integer>> iter = getValidCombos(list); return new Iterator<List<ExternalTupleSet>>() { private List<ExternalTupleSet> next = null; private List<Integer> nextCombo = null; private boolean hasNextCalled = false; private boolean isEmpty = false; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (!iter.hasNext()) { isEmpty = true; return false; } else { nextCombo = iter.next(); List<ExternalTupleSet> indexCombo = Lists .newArrayList(); for (Integer i : nextCombo) { indexCombo.add(list.get(i)); } next = indexCombo; hasNextCalled = true; return true; } } else { return !isEmpty; } } @Override public List<ExternalTupleSet> 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!"); } }; } }
ValidIndexCombinationGenerator { public Iterator<List<ExternalTupleSet>> getValidIndexCombos( List<ExternalTupleSet> indexSet) { Collections.shuffle(indexSet); final List<ExternalTupleSet> list = indexSet; final Iterator<List<Integer>> iter = getValidCombos(list); return new Iterator<List<ExternalTupleSet>>() { private List<ExternalTupleSet> next = null; private List<Integer> nextCombo = null; private boolean hasNextCalled = false; private boolean isEmpty = false; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (!iter.hasNext()) { isEmpty = true; return false; } else { nextCombo = iter.next(); List<ExternalTupleSet> indexCombo = Lists .newArrayList(); for (Integer i : nextCombo) { indexCombo.add(list.get(i)); } next = indexCombo; hasNextCalled = true; return true; } } else { return !isEmpty; } } @Override public List<ExternalTupleSet> 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!"); } }; } ValidIndexCombinationGenerator(TupleExpr query);  ValidIndexCombinationGenerator(List<QueryModelNode> qNodes); }
ValidIndexCombinationGenerator { public Iterator<List<ExternalTupleSet>> getValidIndexCombos( List<ExternalTupleSet> indexSet) { Collections.shuffle(indexSet); final List<ExternalTupleSet> list = indexSet; final Iterator<List<Integer>> iter = getValidCombos(list); return new Iterator<List<ExternalTupleSet>>() { private List<ExternalTupleSet> next = null; private List<Integer> nextCombo = null; private boolean hasNextCalled = false; private boolean isEmpty = false; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (!iter.hasNext()) { isEmpty = true; return false; } else { nextCombo = iter.next(); List<ExternalTupleSet> indexCombo = Lists .newArrayList(); for (Integer i : nextCombo) { indexCombo.add(list.get(i)); } next = indexCombo; hasNextCalled = true; return true; } } else { return !isEmpty; } } @Override public List<ExternalTupleSet> 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!"); } }; } ValidIndexCombinationGenerator(TupleExpr query);  ValidIndexCombinationGenerator(List<QueryModelNode> qNodes); Iterator<List<ExternalTupleSet>> getValidIndexCombos(
			List<ExternalTupleSet> indexSet); }
ValidIndexCombinationGenerator { public Iterator<List<ExternalTupleSet>> getValidIndexCombos( List<ExternalTupleSet> indexSet) { Collections.shuffle(indexSet); final List<ExternalTupleSet> list = indexSet; final Iterator<List<Integer>> iter = getValidCombos(list); return new Iterator<List<ExternalTupleSet>>() { private List<ExternalTupleSet> next = null; private List<Integer> nextCombo = null; private boolean hasNextCalled = false; private boolean isEmpty = false; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { if (!iter.hasNext()) { isEmpty = true; return false; } else { nextCombo = iter.next(); List<ExternalTupleSet> indexCombo = Lists .newArrayList(); for (Integer i : nextCombo) { indexCombo.add(list.get(i)); } next = indexCombo; hasNextCalled = true; return true; } } else { return !isEmpty; } } @Override public List<ExternalTupleSet> 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!"); } }; } ValidIndexCombinationGenerator(TupleExpr query);  ValidIndexCombinationGenerator(List<QueryModelNode> qNodes); Iterator<List<ExternalTupleSet>> getValidIndexCombos(
			List<ExternalTupleSet> indexSet);  }