use of org.eclipse.collections.api.ByteIterable in project eclipse-collections by eclipse.
the class ByteHashSet method chunk.
@Override
public RichIterable<ByteIterable> chunk(int size) {
if (size <= 0) {
throw new IllegalArgumentException("Size for groups must be positive but was: " + size);
}
MutableList<ByteIterable> result = Lists.mutable.empty();
if (this.notEmpty()) {
if (this.size() <= size) {
result.add(ByteSets.mutable.withAll(this));
} else {
ByteIterator iterator = this.byteIterator();
while (iterator.hasNext()) {
MutableByteSet batch = ByteSets.mutable.empty();
for (int i = 0; i < size && iterator.hasNext(); i++) {
batch.add(iterator.next());
}
result.add(batch);
}
}
}
return result;
}
use of org.eclipse.collections.api.ByteIterable in project eclipse-collections by eclipse.
the class AbstractRichIterableTestCase method collectByteWithTarget.
@Test
public void collectByteWithTarget() {
MutableByteCollection target = new ByteArrayList();
ByteIterable result = this.newWith(1, 2, 3, 4).collectByte(PrimitiveFunctions.unboxIntegerToByte(), target);
Assert.assertSame("Target list sent as parameter not returned", target, result);
Assert.assertEquals(ByteHashBag.newBagWith((byte) 1, (byte) 2, (byte) 3, (byte) 4), result.toBag());
}
use of org.eclipse.collections.api.ByteIterable in project eclipse-collections by eclipse.
the class MapIterableTestCase method collectByte.
@Test
public void collectByte() {
MapIterable<String, String> map = this.newMapWithKeysValues("One", "1", "Two", "2", "Three", "3");
ByteIterable actual = map.collectByte(Byte::parseByte);
Assert.assertEquals(ByteHashBag.newBagWith((byte) 1, (byte) 2, (byte) 3), actual.toBag());
}
use of org.eclipse.collections.api.ByteIterable in project eclipse-collections by eclipse.
the class AbstractRichIterableTestCase method collectByte.
@Test
public void collectByte() {
ByteIterable result = this.newWith(1, 2, 3, 4).collectByte(PrimitiveFunctions.unboxIntegerToByte());
Assert.assertEquals(ByteBags.mutable.of((byte) 1, (byte) 2, (byte) 3, (byte) 4), result.toBag());
Assert.assertEquals(ByteBags.mutable.of((byte) 1, (byte) 2, (byte) 3, (byte) 4), ByteBags.mutable.ofAll(result));
}
Aggregations