se.ugli.java.util.ImmutableCollection Maven / Gradle / Ivy
The newest version!
package se.ugli.java.util;
import java.io.Serializable;
import java.util.Collection;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public interface ImmutableCollection extends Iterable, Serializable {
int size();
boolean isEmpty();
boolean contains(Object o);
Object[] toArray();
T[] toArray(T[] a);
Collection toCollection();
default boolean containsAll(final Iterable> c) {
for (final Object o : c)
if (!contains(o))
return false;
return true;
}
@Override
default Spliterator spliterator() {
return Spliterators.spliterator(toArray(), 0);
}
default Stream stream() {
return StreamSupport.stream(spliterator(), false);
}
default Stream parallelStream() {
return StreamSupport.stream(spliterator(), true);
}
}