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

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

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

final class VectorCons extends ConcreteVector
        implements NonEmptyVector, Primitive {
    private final A head;
    private final Vector tail;

    VectorCons(A head, Vector tail) {
        this.head = head;
        this.tail = tail;
    }

    @Override
    public A head() {
        return head;
    }

    @Override
    public int size() {
        return 1 + tail.size();
    }

    @Override
    public A unsafeGet(int index) {
        if (index < 0 || index >= size()) {
            throw new IndexOutOfBoundsException();
        }
        if (index == 0) {
            return head;
        } else {
            return tail.unsafeGet(index - 1);
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy