Search in sources :

Example 1 with ExcludeNullIterableDecorator

use of jetbrains.exodus.entitystore.iterate.ExcludeNullIterableDecorator in project xodus by JetBrains.

the class ExcludeNullStaticTypedEntityIterable method instantiate.

@Override
public Iterable<Entity> instantiate() {
    Iterable<Entity> instantiatedDecorated = decorated.instantiate();
    if (queryEngine.isPersistentIterable(instantiatedDecorated)) {
        EntityIterableBase entityIterableBaseDecorated = ((EntityIterableBase) instantiatedDecorated).getSource();
        if (entityIterableBaseDecorated == EntityIterableBase.EMPTY) {
            return EntityIterableBase.EMPTY;
        }
        return queryEngine.wrap(new ExcludeNullIterableDecorator(entityIterableBaseDecorated.getTransaction(), entityIterableBaseDecorated));
    }
    return () -> new Iterator<Entity>() {

        private Iterator<Entity> iterator = null;

        private Entity next = null;

        @Override
        public boolean hasNext() {
            if (next != null) {
                return true;
            }
            if (iterator == null) {
                iterator = decorated.iterator();
            }
            while (iterator.hasNext() && next == null) {
                next = iterator.next();
            }
            return next != null;
        }

        @Override
        public Entity next() {
            if (hasNext()) {
                Entity result = next;
                next = null;
                return result;
            }
            throw new NoSuchElementException();
        }

        @Override
        public void remove() {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) ExcludeNullIterableDecorator(jetbrains.exodus.entitystore.iterate.ExcludeNullIterableDecorator) 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 ExcludeNullIterableDecorator (jetbrains.exodus.entitystore.iterate.ExcludeNullIterableDecorator)1