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;
}
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();
}
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);
}
}
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;
}
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;
}
Aggregations