use of jetbrains.exodus.entitystore.iterate.binop.AddNullDecoratorIterable in project xodus by JetBrains.
the class AddNullStaticTypedEntityIterable method instantiate.
@Override
public Iterable<Entity> instantiate() {
Iterable<Entity> instantiatedDecorated = decorated.instantiate();
Iterable<Entity> instantiatedNullContainer = nullContainer.instantiate();
if (queryEngine.isPersistentIterable(instantiatedDecorated) && queryEngine.isPersistentIterable(instantiatedNullContainer)) {
EntityIterableBase entityIterableBaseDecorated = ((EntityIterableBase) instantiatedDecorated).getSource();
EntityIterableBase entityIterableBaseNullContainer = ((EntityIterableBase) instantiatedNullContainer).getSource();
return queryEngine.wrap(new AddNullDecoratorIterable(queryEngine.getPersistentStore().getAndCheckCurrentTransaction(), entityIterableBaseDecorated, entityIterableBaseNullContainer));
}
return () -> new Iterator<Entity>() {
private Iterator<Entity> iterator = null;
private Boolean hasNull = null;
@Override
public boolean hasNext() {
if (iterator == null) {
iterator = decorated.iterator();
}
if (iterator.hasNext()) {
return true;
}
if (hasNull == null) {
hasNull = false;
for (Entity entity : nullContainer) {
if (entity == null) {
hasNull = true;
break;
}
}
}
return hasNull;
}
@Override
public Entity next() {
if (hasNext()) {
if (hasNull == null) {
Entity result = iterator.next();
if (result == null) {
hasNull = false;
}
return result;
} else {
hasNull = false;
return null;
}
}
throw new NoSuchElementException();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
Aggregations