All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.marksman.collectionviews.WrappedArrayVector Maven / Gradle / Ivy

There is a newer version: 1.2.3
Show newest version
package dev.marksman.collectionviews;

import java.util.Arrays;

final class WrappedArrayVector extends ConcreteVector
        implements NonEmptyVector, Primitive {
    /**
     * underlying must contain at least one element
     */
    private final A[] underlying;

    WrappedArrayVector(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];
    }

    @Override
    public ImmutableNonEmptyVector toImmutable() {
        A[] copied = Arrays.copyOf(underlying, underlying.length);
        return new ImmutableArrayVector<>(copied);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy