Interface ImmutableCollection<E>

    • Method Detail

      • size

        int size()
        Give the size of this collection.
        Returns:
        The size of this collection.
      • add

        ImmutableCollection<E> add​(E e)
        Create a new collection having the items of this collection plus one new item.
        Parameters:
        e - The items to add.
        Returns:
        The new collection.
      • add

        ImmutableCollection<E> add​(E first,
                                   E second,
                                   E... rest)
        Create a new collection having the items of this collection plus new items.
        Parameters:
        first - The first item to add.
        second - The second item to add.
        rest - The other items to add.
        Returns:
        The new collection.
      • contains

        boolean contains​(E item)
        Indicate if a given item is contained in this collection.
        Parameters:
        item - The item to search for.
        Returns:
        If this item was found in this collection.
        See Also:
        Collection.contains(Object)
      • toCollection

        Collection<E> toCollection()
        Create a read-only java util collection from this collection.
        Returns:
        The collection.
      • isEmpty

        default boolean isEmpty()
        Indicate if this collection is empty.
        Returns:
        If this collection is empty.
      • isNotEmpty

        default boolean isNotEmpty()
        Indicate if this collection contains at least one item.
        Returns:
        If this collection contains any item.
      • addAll

        ImmutableCollection<E> addAll​(Collection<? extends E> items)
        Create a new collection having the items of this collection plus items from another collection.
        Parameters:
        items - The items to add.
        Returns:
        The new collection.
      • addAll

        default ImmutableCollection<E> addAll​(ImmutableCollection<E> items)
        Create a new collection having the items of this collection plus items from another collection.
        Parameters:
        items - The items to add.
        Returns:
        The new collection.
      • addAll

        default ImmutableCollection<E> addAll​(E[] items)
        Create a new collection having the items of this collection plus items from an array.
        Parameters:
        items - The items to add.
        Returns:
        The new collection.
      • forEachUntil

        default void forEachUntil​(Predicate<E> loop)
        Apply a function for each item of this collection until this function return false.
        Parameters:
        loop - The function to call with each item of this collection.
      • forEach

        default void forEach​(BiFunction<E,​Integer,​Boolean> loop)
        Apply a function for each item of this collection until this function return false.
        Parameters:
        loop - The function to call with each item of this collection and its index.
      • reduce

        default <R> R reduce​(BiFunction<R,​E,​R> reducer,
                             R initialValue)
        Apply a reducer to this collection.
        Type Parameters:
        R - The output type of the reducer.
        Parameters:
        reducer - The reducer.
        initialValue - The initial value.
        Returns:
        The reduced value.
        See Also:
        Stream.reduce(Object, java.util.function.BinaryOperator)
      • some

        default boolean some​(Predicate<E> predicate)
        Test if one of the items of this collection matches a given predicate.
        Parameters:
        predicate - The predicate to use.
        Returns:
        If one of the items of this collection matches the predicate.
      • every

        default boolean every​(Predicate<E> predicate)
        Test if all the items of this collection match a given predicate.
        Parameters:
        predicate - The predicate to use.
        Returns:
        If all the items of this collection match the predicate.
      • find

        default Optional<E> find​(Predicate<E> predicate)
        Find the first item that matches a given predicate.
        Parameters:
        predicate - The predicate with which to test this collection's items.
        Returns:
        The item in an optional. This optional will be empty if no item matched.
      • findIndex

        default int findIndex​(Predicate<E> predicate)
        Find the number of iterations that were needed to find an item matching the given predicate.
        Parameters:
        predicate - The predicate with which to test this collection's items.
        Returns:
        The number of iterations, or -1 if no item matched the predicate.
      • doesNotContain

        default boolean doesNotContain​(E item)
        Indicate if a given item is not contained in this collection.
        Parameters:
        item - The item to search for.
        Returns:
        If this item was not found in this collection.
        See Also:
        contains(Object)
      • toArray

        E[] toArray​(E[] a)
        Copy the content of this collection in an array.
        Parameters:
        a - The array to attempt copy into.
        Returns:
        An array containing the items of this collection. Can be different than a if a was not large enough.
        See Also:
        Collection.toArray(Object[])
      • toArray

        default E[] toArray​(IntFunction<E[]> a)
        Transforms this collection into an array.
        Parameters:
        a - The function that creates an array of the correct type given its size as input.
        Returns:
        The array containing the items in this collection.
      • getFirst

        default <R> Optional<R> getFirst​(Function<E,​Optional<R>> optionalResult)
        When all the items of this collection can produce an optional result via a method, returns the first non empty result.
        Type Parameters:
        R - The type of the value contained in the created Optional.
        Parameters:
        optionalResult - The function creating the optional result from an item in the collection. Will only be called while the current result is an empty optional.
        Returns:
        The optional with the first non empty result, or an empty optional if all results were empty.