dev.marksman.collectionviews.ImmutableNonEmptySetAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of collection-views Show documentation
Show all versions of collection-views Show documentation
Low overhead, protected views over Java collections
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());
}
}