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

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);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy