Search in sources :

Example 1 with ByteIterator

use of org.eclipse.collections.api.iterator.ByteIterator 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 ByteIterator

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

the class AbstractByteSetTestCase method byteIterator_throws.

@Override
@Test(expected = NoSuchElementException.class)
public void byteIterator_throws() {
    MutableByteSet set = this.newWith((byte) 0, (byte) 1, (byte) 31, (byte) -1, (byte) -31);
    ByteIterator iterator = set.byteIterator();
    while (iterator.hasNext()) {
        iterator.next();
    }
    iterator.next();
}
Also used : ByteIterator(org.eclipse.collections.api.iterator.ByteIterator) MutableByteSet(org.eclipse.collections.api.set.primitive.MutableByteSet) Test(org.junit.Test)

Example 3 with ByteIterator

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

the class ByteHashSet method appendString.

@Override
public void appendString(Appendable appendable, String start, String separator, String end) {
    try {
        appendable.append(start);
        int count = 0;
        ByteIterator iterator = this.byteIterator();
        while (iterator.hasNext()) {
            if (count > 0) {
                appendable.append(separator);
            }
            count++;
            appendable.append(String.valueOf(iterator.next()));
        }
        appendable.append(end);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : MutableByteIterator(org.eclipse.collections.api.iterator.MutableByteIterator) ByteIterator(org.eclipse.collections.api.iterator.ByteIterator) IOException(java.io.IOException)

Example 4 with ByteIterator

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

the class ByteHashSet method injectInto.

@Override
public <T> T injectInto(T injectedValue, ObjectByteToObjectFunction<? super T, ? extends T> function) {
    T result = injectedValue;
    ByteIterator iterator = this.byteIterator();
    while (iterator.hasNext()) {
        result = function.valueOf(result, iterator.next());
    }
    return result;
}
Also used : MutableByteIterator(org.eclipse.collections.api.iterator.MutableByteIterator) ByteIterator(org.eclipse.collections.api.iterator.ByteIterator)

Example 5 with ByteIterator

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

the class ByteHashSet method toArray.

@Override
public byte[] toArray() {
    byte[] array = new byte[this.size()];
    int index = 0;
    ByteIterator iterator = this.byteIterator();
    while (iterator.hasNext()) {
        byte nextByte = iterator.next();
        array[index] = nextByte;
        index++;
    }
    return array;
}
Also used : MutableByteIterator(org.eclipse.collections.api.iterator.MutableByteIterator) ByteIterator(org.eclipse.collections.api.iterator.ByteIterator)

Aggregations

ByteIterator (org.eclipse.collections.api.iterator.ByteIterator)12 MutableByteIterator (org.eclipse.collections.api.iterator.MutableByteIterator)8 Test (org.junit.Test)4 MutableByteSet (org.eclipse.collections.api.set.primitive.MutableByteSet)3 ImmutableByteSet (org.eclipse.collections.api.set.primitive.ImmutableByteSet)2 IOException (java.io.IOException)1 ByteIterable (org.eclipse.collections.api.ByteIterable)1 LazyByteIterable (org.eclipse.collections.api.LazyByteIterable)1