Search in sources :

Example 1 with AddNullDecoratorIterable

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();
        }
    };
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) AddNullDecoratorIterable(jetbrains.exodus.entitystore.iterate.binop.AddNullDecoratorIterable) EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase) Iterator(java.util.Iterator) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

Iterator (java.util.Iterator)1 NoSuchElementException (java.util.NoSuchElementException)1 Entity (jetbrains.exodus.entitystore.Entity)1 EntityIterableBase (jetbrains.exodus.entitystore.iterate.EntityIterableBase)1 AddNullDecoratorIterable (jetbrains.exodus.entitystore.iterate.binop.AddNullDecoratorIterable)1