final HashMap<Item, QueryRDFTerm> rdfHash = new HashMap<Item, QueryRDFTerm>();
final LinkedHashSet<Operator> rdfTermToJoin = new LinkedHashSet<Operator>();
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
final Node n = node.jjtGetChild(i);
if (n instanceof ASTTripleSet) {
final QueryRDFTerm rdft = (QueryRDFTerm) n.jjtAccept(
this, rdfHash);
rdfTermToJoin.add(rdft);
} else if (n instanceof ASTUnionConstraint
|| n instanceof ASTGraphConstraint) {
numberUnionOrGraphConstraints++;
}
}
int numberJoinPartner = numberUnionOrGraphConstraints;
if (rdfTermToJoin.size() > 0) {
numberJoinPartner++;
}
Operator testOP = null;
if (numberJoinPartner > 1) {
final Join joinOp = new Join();
int j = 0;
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
final Node n = node.jjtGetChild(i);
if (n instanceof ASTUnionConstraint
|| n instanceof ASTGraphConstraint) {
testOP = (Operator) n.jjtAccept(
this, data);
if (testOP != null) {
joinOp.addSucceedingOperator(new OperatorIDTuple<Operator>(
testOP, j));
}
j++;
}
}
if (rdfTermToJoin.size() > 0) {
final TripleContainer opContainer = new TripleContainer(
rdfTermToJoin);
joinOp.addSucceedingOperator(new OperatorIDTuple<Operator>(
opContainer, j));
}
testOP = joinOp;
} else { // There should be only triple patterns or one
// ASTUnionConstraint / ASTGraphConstraint
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
final Node n = node.jjtGetChild(i);
if (n instanceof ASTTripleSet) {
final TripleContainer opContainer = new TripleContainer(
rdfTermToJoin);
testOP = opContainer;
break;
} else if (n instanceof ASTUnionConstraint
|| n instanceof ASTGraphConstraint) {
testOP = (Operator) n.jjtAccept(
this, data);
break;
}
}
}
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
final Node n = node.jjtGetChild(i);
if (n instanceof ASTOptionalConstraint) {
final Optional optional = new Optional();
if (testOP != null) {
optional.addSucceedingOperator(new OperatorIDTuple<Operator>(
testOP, 0));
}
testOP = (Operator) n.jjtAccept(
this, null);
if (testOP != null) {
optional.addSucceedingOperator(new OperatorIDTuple<Operator>(
testOP, 1));
}
testOP = optional;
}
}
for (int i = 0; i < node.jjtGetNumChildren(); i++) {
final Node n = node.jjtGetChild(i);
Operator filterOp = null;
if (n instanceof ASTFilterConstraint) {
filterOp = (Operator) n.jjtAccept(
this, data);
if (filterOp != null) {
filterOp.addSucceedingOperator(new OperatorIDTuple<Operator>(
testOP, 0));