@SuppressWarnings("unchecked")
@Override
public QueryResult process(final QueryResult bindings, final int operandID) {
bindings.materialize();
this.comp.setVariables(this.intersectionVariables);
final QueryResult oldLeft = this.left;
final QueryResult oldRight = this.right;
if (operandID == 0) {
if (this.left == null) {
this.left = bindings;
} else {
this.left = QueryResult.createInstance(new MergeIterator<Bindings>(this.comp, this.left.iterator(), bindings.iterator()));
}
} else if (operandID == 1) {
if (this.right == null) {
this.right = bindings;
} else {
this.right = QueryResult.createInstance(new MergeIterator<Bindings>(this.comp, this.right.iterator(), bindings.iterator()));
}
} else {
System.err.println("MergeJoin is a binary operator, but received the operand number "
+ operandID);
}
if (this.left != null && this.right != null) {
this.left.materialize();
this.right.materialize();
final Iterator<Bindings> leftIterator = (operandID == 0 && oldLeft != null) ? new MinusIterator(
bindings.iterator(), oldLeft.iterator())
: this.left.iterator();
final QueryResult rightLocal = (operandID == 1 && oldRight != null) ? QueryResult
.createInstance(new MinusIterator(bindings.iterator(),
oldRight.iterator()))
: this.right;
final ParallelIterator<Bindings> currentResult = (this.intersectionVariables
.size() == 0) ? MergeJoin.cartesianProductIterator(
leftIterator, rightLocal) : MergeJoin.mergeJoinIterator(
leftIterator, rightLocal.iterator(), this.comp,
this.intersectionVariables, this.bindingsFactory);
if (currentResult != null && currentResult.hasNext()) {
final QueryResult result = QueryResult
.createInstance(new ParallelIterator<Bindings>() {
int number = 0;
@Override