2
* Copyright 2011 Goldman Sachs.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
package com.gs.collections.impl.lazy;
19
import java.util.Iterator;
21
import com.gs.collections.api.RichIterable;
22
import com.gs.collections.api.block.procedure.Procedure;
23
import com.gs.collections.api.block.procedure.Procedure2;
24
import com.gs.collections.api.block.procedure.primitive.ObjectIntProcedure;
25
import com.gs.collections.impl.lazy.iterator.ChunkIterator;
26
import com.gs.collections.impl.utility.internal.IterableIterate;
27
import net.jcip.annotations.Immutable;
30
* A ChunkIterable is an iterable that partitions a source iterable into fixed size chunks as it iterates.
33
public class ChunkIterable<T>
34
extends AbstractLazyIterable<RichIterable<T>>
36
private final Iterable<T> iterable;
37
private final int size;
39
public ChunkIterable(Iterable<T> iterable, int size)
43
throw new IllegalArgumentException("Size for groups must be positive but was: " + size);
46
this.iterable = iterable;
50
public Iterator<RichIterable<T>> iterator()
52
return new ChunkIterator<T>(this.iterable, this.size);
55
public void forEach(Procedure<? super RichIterable<T>> procedure)
57
IterableIterate.forEach(this, procedure);
60
public void forEachWithIndex(ObjectIntProcedure<? super RichIterable<T>> objectIntProcedure)
62
IterableIterate.forEachWithIndex(this, objectIntProcedure);
65
public <P> void forEachWith(Procedure2<? super RichIterable<T>, ? super P> procedure, P parameter)
67
IterableIterate.forEachWith(this, procedure, parameter);