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

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

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

import dev.marksman.enhancediterables.ImmutableFiniteIterable;

import java.util.Iterator;

import static dev.marksman.collectionviews.ProtectedIterator.protectedIterator;

final class ImmutableNonEmptySetAdapter extends ConcreteSet
        implements ImmutableNonEmptySet, Primitive {
    private final ImmutableSet underlying;

    ImmutableNonEmptySetAdapter(ImmutableSet underlying) {
        this.underlying = underlying;
    }

    @Override
    public A head() {
        return underlying.iterator().next();
    }

    @Override
    public ImmutableFiniteIterable tail() {
        Iterator iterator = iterator();
        iterator.next();
        return () -> iterator;
    }

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

    @Override
    public boolean contains(A element) {
        return underlying.contains(element);
    }

    @Override
    public Iterator iterator() {
        return protectedIterator(underlying.iterator());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy