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

dev.marksman.collectionviews.WrappedSet 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 java.util.Set;

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

final class WrappedSet extends ConcreteSet
        implements NonEmptySet, Primitive {

    /**
     * underlying must contain at least one element
     */
    private final java.util.Set underlying;

    WrappedSet(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 boolean isEmpty() {
        return false;
    }

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy