Search in sources :

Example 1 with ByteIterable

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;
}
Also used : MutableByteIterator(org.eclipse.collections.api.iterator.MutableByteIterator) ByteIterator(org.eclipse.collections.api.iterator.ByteIterator) LazyByteIterable(org.eclipse.collections.api.LazyByteIterable) ByteIterable(org.eclipse.collections.api.ByteIterable) MutableByteSet(org.eclipse.collections.api.set.primitive.MutableByteSet)

Example 2 with ByteIterable

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());
}
Also used : ByteArrayList(org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList) ByteIterable(org.eclipse.collections.api.ByteIterable) MutableByteCollection(org.eclipse.collections.api.collection.primitive.MutableByteCollection) Test(org.junit.Test)

Example 3 with ByteIterable

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());
}
Also used : ByteIterable(org.eclipse.collections.api.ByteIterable) Test(org.junit.Test)

Example 4 with ByteIterable

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));
}
Also used : ByteIterable(org.eclipse.collections.api.ByteIterable) Test(org.junit.Test)

Aggregations

ByteIterable (org.eclipse.collections.api.ByteIterable)4 Test (org.junit.Test)3 LazyByteIterable (org.eclipse.collections.api.LazyByteIterable)1 MutableByteCollection (org.eclipse.collections.api.collection.primitive.MutableByteCollection)1 ByteIterator (org.eclipse.collections.api.iterator.ByteIterator)1 MutableByteIterator (org.eclipse.collections.api.iterator.MutableByteIterator)1 MutableByteSet (org.eclipse.collections.api.set.primitive.MutableByteSet)1 ByteArrayList (org.eclipse.collections.impl.list.mutable.primitive.ByteArrayList)1