dev.marksman.collectionviews.ImmutableArrayVector 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;
@SuppressWarnings("unused")
final class ImmutableArrayVector extends ConcreteVector
implements ImmutableNonEmptyVector, Primitive {
/**
* underlying must contain at least one element.
*/
private final A[] underlying;
ImmutableArrayVector(A[] underlying) {
this.underlying = underlying;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public int size() {
return underlying.length;
}
@Override
public A unsafeGet(int index) {
if (index < 0 || index >= underlying.length) {
throw new IndexOutOfBoundsException();
}
return underlying[index];
}
}