this.bindings1 = new CollectionImplementation<Bindings>(MergeJoin.MEMORYLIMIT);
this.bindings2 = new CollectionImplementation<Bindings>(MergeJoin.MEMORYLIMIT);
Iterator<Bindings> currentBinding2 = null;
final Bindings bindings = this.b1;
do {
this.bindings1.add(this.b1);
if (!ssb1it.hasNext()) {
this.b1 = null;
this.processFurther = false;
break;
}
this.b1 = ssb1it.next();
} while(comp.compare(this.b1, bindings) == 0);
do {
this.bindings2.add(this.b2);
if (!ssb2it.hasNext()) {
this.processFurther = false;
// rest from ssb1:
currentBinding2 = new Iterator<Bindings>() {
Bindings zb1 = b1;
@Override
public boolean hasNext() {
return (this.zb1 != null || ssb1it.hasNext());
}
@Override
public Bindings next() {
if (this.zb1 != null) {
final Bindings zzb1 = this.zb1;
this.zb1 = null;
return zzb1;
}
return ssb1it.next();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
break;
}
this.b2 = ssb2it.next();
} while (comp.compare(this.b2, bindings) == 0);
final Iterator<Bindings> currentBinding3 = currentBinding2;
this.currentBinding = new Iterator<Bindings>() {
final Iterator<Bindings> itb1 = bindings1.iterator();
Iterator<Bindings> itb2 = bindings2.iterator();
Bindings zb1 = this.itb1.next();
Iterator<Bindings> restFrom1 = currentBinding3;
@Override
public boolean hasNext() {
return this.itb1.hasNext()
|| this.itb2.hasNext()
|| (this.restFrom1 != null && this.restFrom1
.hasNext());
}
@Override
public Bindings next() {
if (!this.hasNext()) {
return null;
}
if (!(this.itb1.hasNext() || this.itb2.hasNext())) {
if (this.restFrom1 != null && this.restFrom1.hasNext()) {
return this.restFrom1.next();
}
}
if (!this.itb2.hasNext()) {
this.zb1 = this.itb1.next();
this.itb2 = bindings2.iterator();
}
final Bindings bnew = this.zb1.clone();
final Bindings zb2 = this.itb2.next();
bnew.addAll(zb2);
bnew.addAllTriples(zb2);
bnew.addAllPresortingNumbers(zb2);
return bnew;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
return;
} else if (compare < 0) {
if (ssb1it.hasNext()) {
this.currentBinding = new Iterator<Bindings>() {
@Override
public boolean hasNext() {
return (b1 != null && comp.compare(b1, b2) < 0);
}
@Override
public Bindings next() {
if (comp.compare(b1, b2) >= 0) {
return null;
}
final Bindings zb1 = b1;
b1 = ssb1it.next();
if (b1 == null) {
processFurther = false;
}
return zb1;
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
return;
} else {
this.processFurther = false;
}
} else if (compare > 0) {
if (ssb2it.hasNext()) {
this.b2 = ssb2it.next();
} else {
this.currentBinding = new Iterator<Bindings>() {
Bindings zb1 = b1;
@Override
public boolean hasNext() {
return (this.zb1 != null || ssb1it.hasNext());
}
@Override
public Bindings next() {
if (this.zb1 != null) {
final Bindings zzb1 = this.zb1;
this.zb1 = null;
return zzb1;
}
return ssb1it.next();
}