Search in sources :

Example 6 with IntIterator

use of org.eclipse.collections.api.iterator.IntIterator in project eclipse-collections by eclipse.

the class CodePointAdapter method chunk.

@Override
public RichIterable<IntIterable> chunk(int size) {
    if (size <= 0) {
        throw new IllegalArgumentException("Size for groups must be positive but was: " + size);
    }
    MutableList<IntIterable> result = Lists.mutable.empty();
    if (this.notEmpty()) {
        if (this.size() <= size) {
            result.add(IntLists.immutable.withAll(this));
        } else {
            IntIterator iterator = this.intIterator();
            while (iterator.hasNext()) {
                MutableIntList batch = IntLists.mutable.empty();
                for (int i = 0; i < size && iterator.hasNext(); i++) {
                    batch.add(iterator.next());
                }
                result.add(CodePointList.from(batch));
            }
        }
    }
    return result.toImmutable();
}
Also used : IntIterator(org.eclipse.collections.api.iterator.IntIterator) MutableIntList(org.eclipse.collections.api.list.primitive.MutableIntList) IntIterable(org.eclipse.collections.api.IntIterable) AbstractIntIterable(org.eclipse.collections.impl.primitive.AbstractIntIterable) ReverseIntIterable(org.eclipse.collections.impl.lazy.primitive.ReverseIntIterable) LazyIntIterable(org.eclipse.collections.api.LazyIntIterable)

Example 7 with IntIterator

use of org.eclipse.collections.api.iterator.IntIterator in project eclipse-collections by eclipse.

the class CodePointAdapter method zipInt.

/**
 * @since 9.1.
 */
@Override
public ImmutableList<IntIntPair> zipInt(IntIterable iterable) {
    int size = this.size();
    int othersize = iterable.size();
    MutableList<IntIntPair> target = Lists.mutable.withInitialCapacity(Math.min(size, othersize));
    IntIterator iterator = iterable.intIterator();
    for (int i = 0; i < size && i < othersize; i++) {
        target.add(PrimitiveTuples.pair(this.get(i), iterator.next()));
    }
    return target.toImmutable();
}
Also used : IntIterator(org.eclipse.collections.api.iterator.IntIterator) IntIntPair(org.eclipse.collections.api.tuple.primitive.IntIntPair)

Example 8 with IntIterator

use of org.eclipse.collections.api.iterator.IntIterator in project eclipse-collections by eclipse.

the class CodePointList method zipInt.

/**
 * @since 9.1.
 */
@Override
public ImmutableList<IntIntPair> zipInt(IntIterable iterable) {
    int size = this.size();
    int othersize = iterable.size();
    MutableList<IntIntPair> target = Lists.mutable.withInitialCapacity(Math.min(size, othersize));
    IntIterator iterator = iterable.intIterator();
    for (int i = 0; i < size && i < othersize; i++) {
        target.add(PrimitiveTuples.pair(this.get(i), iterator.next()));
    }
    return target.toImmutable();
}
Also used : IntIterator(org.eclipse.collections.api.iterator.IntIterator) IntIntPair(org.eclipse.collections.api.tuple.primitive.IntIntPair)

Example 9 with IntIterator

use of org.eclipse.collections.api.iterator.IntIterator in project eclipse-collections by eclipse.

the class IntIntervalTest method iterator.

@Test
public void iterator() {
    IntIterator iterator = this.intInterval.intIterator();
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(1L, iterator.next());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(2L, iterator.next());
    Assert.assertTrue(iterator.hasNext());
    Assert.assertEquals(3L, iterator.next());
    Assert.assertFalse(iterator.hasNext());
}
Also used : IntIterator(org.eclipse.collections.api.iterator.IntIterator) Test(org.junit.Test)

Example 10 with IntIterator

use of org.eclipse.collections.api.iterator.IntIterator in project eclipse-collections by eclipse.

the class IntInterval method zipInt.

@Override
public ImmutableList<IntIntPair> zipInt(IntIterable iterable) {
    int size = this.size();
    int othersize = iterable.size();
    MutableList<IntIntPair> target = Lists.mutable.withInitialCapacity(Math.min(size, othersize));
    IntIterator iterator = this.intIterator();
    IntIterator otherIterator = iterable.intIterator();
    for (int i = 0; i < size && otherIterator.hasNext(); i++) {
        target.add(PrimitiveTuples.pair(iterator.next(), otherIterator.next()));
    }
    return target.toImmutable();
}
Also used : IntIterator(org.eclipse.collections.api.iterator.IntIterator) IntIntPair(org.eclipse.collections.api.tuple.primitive.IntIntPair)

Aggregations

IntIterator (org.eclipse.collections.api.iterator.IntIterator)10 IntIntPair (org.eclipse.collections.api.tuple.primitive.IntIntPair)3 Test (org.junit.Test)3 IntIterable (org.eclipse.collections.api.IntIterable)1 LazyIntIterable (org.eclipse.collections.api.LazyIntIterable)1 MutableIntCollection (org.eclipse.collections.api.collection.primitive.MutableIntCollection)1 MutableIntIterator (org.eclipse.collections.api.iterator.MutableIntIterator)1 MutableIntList (org.eclipse.collections.api.list.primitive.MutableIntList)1 IntObjectPair (org.eclipse.collections.api.tuple.primitive.IntObjectPair)1 ReverseIntIterable (org.eclipse.collections.impl.lazy.primitive.ReverseIntIterable)1 AbstractIntIterable (org.eclipse.collections.impl.primitive.AbstractIntIterable)1 IntHashSet (org.eclipse.collections.impl.set.mutable.primitive.IntHashSet)1