if (!visited.contains(tp)) {
BasicIndexScan idx;
if (succ.size() == 1) {
if (succ.size() == 1
&& succ.get(0).getOperator() instanceof Join) {
final Join tj = findTopJoin((Join) succ.get(0)
.getOperator());
if (tj != null) {
// final List<Join> bottomJoins = new
// LinkedList<Join>();
// final boolean complete = findBottomJoins(tj,
// null,
// bottomJoins);
// final List<TriplePattern> tps =
// collectPredTPs(tj,
// bottomJoins, visited);
final List<TriplePattern> tps = new LinkedList<TriplePattern>();
final boolean complete = collectPredTPs(tj, tps);
visited.addAll(tps);
idx = ic.newIndexScan(null, tps, null);
final HashSet<Variable> hsv = new HashSet<Variable>();
for (final TriplePattern stp : tps) {
hsv.addAll(stp.getUnionVariables());
}
idx.setIntersectionVariables(hsv);
idx.setUnionVariables(hsv);
if (complete) {
idx.setSucceedingOperators(tj
.getSucceedingOperators());
} else {
for (final BasicOperator prec : tj
.getPrecedingOperators()) {
if (collectPredTPs(prec,
new LinkedList<TriplePattern>())) {
final int operandID = prec
.getOperatorIDTuple(tj).getId();