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

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

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

import dev.marksman.enhancediterables.FiniteIterable;

import java.util.Iterator;

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


final class NonEmptySetAdapter extends ConcreteSet implements NonEmptySet {
    private final Set underlying;

    NonEmptySetAdapter(Set underlying) {
        this.underlying = underlying;
    }

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

    @Override
    public FiniteIterable 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