Search in sources :

Example 16 with AbstractIterator

use of com.google.common.collect.AbstractIterator in project Wurst-MC-1.12 by Wurst-Imperium.

the class BlockUtils method getValidBlocks.

public static Iterable<BlockPos> getValidBlocks(int blockRange, BlockValidator validator) {
    BlockPos playerPos = new BlockPos(RotationUtils.getEyesPos());
    BlockPos min = playerPos.add(-blockRange, -blockRange, -blockRange);
    BlockPos max = playerPos.add(blockRange, blockRange, blockRange);
    return () -> new AbstractIterator<BlockPos>() {

        private BlockPos last;

        private BlockPos computeNextUnchecked() {
            if (last == null) {
                last = min;
                return last;
            }
            int x = last.getX();
            int y = last.getY();
            int z = last.getZ();
            if (z < max.getZ())
                z++;
            else if (x < max.getX()) {
                z = min.getZ();
                x++;
            } else if (y < max.getY()) {
                z = min.getZ();
                x = min.getX();
                y++;
            } else
                return null;
            last = new BlockPos(x, y, z);
            return last;
        }

        @Override
        protected BlockPos computeNext() {
            BlockPos pos;
            while ((pos = computeNextUnchecked()) != null) {
                // skip air blocks
                if (WBlock.getMaterial(pos) == Material.AIR)
                    continue;
                // check if block is valid
                if (!validator.isValid(pos))
                    continue;
                return pos;
            }
            return endOfData();
        }
    };
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) AbstractIterator(com.google.common.collect.AbstractIterator)

Example 17 with AbstractIterator

use of com.google.common.collect.AbstractIterator in project DynamicSurroundings by OreCruncher.

the class BlockPosHelper method getAllInBoxMutable.

/**
 * Like getAllInBox but reuses a single MutableBlockPos instead. If this method
 * is used, the resulting BlockPos instances can only be used inside the
 * iteration loop.
 *
 * NOTE: This is similar to the logic in Forge. Difference is that it favors
 * iterating along the Y axis first before X/Z. Goal is to maximize chunk
 * caching for area scanning.
 */
public static Iterable<BlockPos.MutableBlockPos> getAllInBoxMutable(BlockPos from, BlockPos to) {
    final BlockPos blockpos = createMinPoint(from, to);
    final BlockPos blockpos1 = createMaxPoint(from, to);
    return () -> new AbstractIterator<BlockPos.MutableBlockPos>() {

        private BlockPos.MutableBlockPos theBlockPos;

        @Override
        protected BlockPos.MutableBlockPos computeNext() {
            if (this.theBlockPos == null) {
                this.theBlockPos = new BlockPos.MutableBlockPos(blockpos.getX(), blockpos.getY(), blockpos.getZ());
                return this.theBlockPos;
            } else if (this.theBlockPos.equals(blockpos1)) {
                return endOfData();
            } else {
                int i = this.theBlockPos.getX();
                int j = this.theBlockPos.getY();
                int k = this.theBlockPos.getZ();
                if (j < blockpos1.getY()) {
                    ++j;
                } else if (i < blockpos1.getX()) {
                    j = blockpos.getY();
                    ++i;
                } else if (k < blockpos1.getZ()) {
                    i = blockpos.getX();
                    j = blockpos.getY();
                    ++k;
                }
                this.theBlockPos.setPos(i, j, k);
                return this.theBlockPos;
            }
        }
    };
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) AbstractIterator(com.google.common.collect.AbstractIterator)

Example 18 with AbstractIterator

use of com.google.common.collect.AbstractIterator in project presto by prestodb.

the class TestSelectiveOrcReader method skipEvery.

private static <T> Iterable<T> skipEvery(int n, Iterable<T> iterable) {
    return () -> new AbstractIterator<T>() {

        private final Iterator<T> delegate = iterable.iterator();

        private int position;

        @Override
        protected T computeNext() {
            while (true) {
                if (!delegate.hasNext()) {
                    return endOfData();
                }
                T next = delegate.next();
                position++;
                if (position <= n) {
                    return next;
                }
                position = 0;
            }
        }
    };
}
Also used : TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) Iterator(java.util.Iterator) AbstractIterator(com.google.common.collect.AbstractIterator) AbstractIterator(com.google.common.collect.AbstractIterator)

Example 19 with AbstractIterator

use of com.google.common.collect.AbstractIterator in project presto by prestodb.

the class AbstractTestParquetReader method skipEvery.

private static <T> Iterable<T> skipEvery(int n, Iterable<T> iterable) {
    return () -> new AbstractIterator<T>() {

        private final Iterator<T> delegate = iterable.iterator();

        private int position;

        @Override
        protected T computeNext() {
            while (true) {
                if (!delegate.hasNext()) {
                    return endOfData();
                }
                T next = delegate.next();
                position++;
                if (position <= n) {
                    return next;
                }
                position = 0;
            }
        }
    };
}
Also used : BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) AbstractIterator(com.google.common.collect.AbstractIterator) AbstractSequentialIterator(com.google.common.collect.AbstractSequentialIterator) Iterator(java.util.Iterator) AbstractIterator(com.google.common.collect.AbstractIterator)

Example 20 with AbstractIterator

use of com.google.common.collect.AbstractIterator in project presto by prestodb.

the class AbstractTestOrcReader method skipEvery.

private static <T> Iterable<T> skipEvery(int n, Iterable<T> iterable) {
    return () -> new AbstractIterator<T>() {

        private final Iterator<T> delegate = iterable.iterator();

        private int position;

        @Override
        protected T computeNext() {
            while (true) {
                if (!delegate.hasNext()) {
                    return endOfData();
                }
                T next = delegate.next();
                position++;
                if (position <= n) {
                    return next;
                }
                position = 0;
            }
        }
    };
}
Also used : TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) Iterator(java.util.Iterator) AbstractIterator(com.google.common.collect.AbstractIterator) AbstractIterator(com.google.common.collect.AbstractIterator)

Aggregations

AbstractIterator (com.google.common.collect.AbstractIterator)55 IOException (java.io.IOException)15 Iterator (java.util.Iterator)14 Map (java.util.Map)8 ArrayList (java.util.ArrayList)7 List (java.util.List)6 File (java.io.File)5 EOFException (java.io.EOFException)4 Collection (java.util.Collection)4 HashSet (java.util.HashSet)4 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)3 SMALLINT (com.facebook.presto.common.type.SmallintType.SMALLINT)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 Deque (java.util.Deque)3 Set (java.util.Set)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)3 Test (org.junit.Test)3 TopicMetadata (co.cask.cdap.messaging.TopicMetadata)2 TopicId (co.cask.cdap.proto.id.TopicId)2