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

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

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

import com.jnape.palatable.lambda.functions.builtin.fn2.ToCollection;

import java.util.ArrayList;
import java.util.List;

final class WrappedListVector extends ConcreteVector
        implements NonEmptyVector, Primitive {
    /**
     * underlying must contain at least one element
     */
    private final List underlying;

    WrappedListVector(List underlying) {
        this.underlying = underlying;
    }

    @Override
    public boolean isEmpty() {
        return false;
    }

    @Override
    public int size() {
        return underlying.size();
    }

    @Override
    public A unsafeGet(int index) {
        return underlying.get(index);
    }

    @Override
    public ImmutableNonEmptyVector toImmutable() {
        ArrayList copied = ToCollection.toCollection(ArrayList::new, underlying);
        return new ImmutableListVector<>(copied);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy