Search in sources :

Example 1 with CharIterator

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

the class CharAdapter method chunk.

@Override
public RichIterable<CharIterable> chunk(int size) {
    if (size <= 0) {
        throw new IllegalArgumentException("Size for groups must be positive but was: " + size);
    }
    MutableList<CharIterable> result = Lists.mutable.empty();
    if (this.notEmpty()) {
        CharIterator iterator = this.charIterator();
        while (iterator.hasNext()) {
            MutableCharList batch = CharLists.mutable.empty();
            for (int i = 0; i < size && iterator.hasNext(); i++) {
                batch.add(iterator.next());
            }
            result.add(batch);
        }
    }
    return result;
}
Also used : MutableCharList(org.eclipse.collections.api.list.primitive.MutableCharList) LazyCharIterable(org.eclipse.collections.api.LazyCharIterable) ReverseCharIterable(org.eclipse.collections.impl.lazy.primitive.ReverseCharIterable) CharIterable(org.eclipse.collections.api.CharIterable) AbstractCharIterable(org.eclipse.collections.impl.primitive.AbstractCharIterable) CharIterator(org.eclipse.collections.api.iterator.CharIterator)

Example 2 with CharIterator

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

the class CharAdapter method zipChar.

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

Aggregations

CharIterator (org.eclipse.collections.api.iterator.CharIterator)2 CharIterable (org.eclipse.collections.api.CharIterable)1 LazyCharIterable (org.eclipse.collections.api.LazyCharIterable)1 MutableCharList (org.eclipse.collections.api.list.primitive.MutableCharList)1 CharCharPair (org.eclipse.collections.api.tuple.primitive.CharCharPair)1 ReverseCharIterable (org.eclipse.collections.impl.lazy.primitive.ReverseCharIterable)1 AbstractCharIterable (org.eclipse.collections.impl.primitive.AbstractCharIterable)1