dev.marksman.collectionviews.VectorIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of collection-views Show documentation
Show all versions of collection-views Show documentation
Low overhead, protected views over Java collections
package dev.marksman.collectionviews;
import java.util.Iterator;
import java.util.NoSuchElementException;
final class VectorIterator implements Iterator {
private final Vector underlying;
private int index;
VectorIterator(Vector underlying) {
this.underlying = underlying;
index = 0;
}
@Override
public boolean hasNext() {
return index < underlying.size();
}
@Override
public A next() {
if (index >= underlying.size()) {
throw new NoSuchElementException();
}
A result = underlying.unsafeGet(index);
index += 1;
return result;
}
}