Interface ImmutableCollection<E>

Type Parameters:
E - the element type
All Superinterfaces:
Iterable<E>, ReadOnlyCollection<E>
All Known Subinterfaces:
ImmutableList<E>, ImmutableNavigableSet<E>, ImmutableSequencedCollection<E>, ImmutableSequencedSet<E>, ImmutableSet<E>, ImmutableSortedSet<E>
All Known Implementing Classes:
ChampSet, ChampVectorSet, ImmutableSetFacade, RedBlackSet, VectorList

public interface ImmutableCollection<E> extends ReadOnlyCollection<E>
An interface to an immutable collection; the implementation guarantees that the state of the collection does not change.
  • Method Details

    • add

      Returns a copy of this collection that contains all elements of this collection and also the specified element.

      A collection may prevent that the same element can be added more than once.

      Parameters:
      element - an element
      Returns:
      this collection instance if it already contains the element, or a different collection instance with the element added
    • addAll

      Returns a copy of this collection that contains all elements of this collection and also all elements of the specified collection.

      A collection may prevent that the same element can be added more than once.

      Parameters:
      c - a collection to be added to this collection
      Returns:
      this collection instance if it already contains the elements, or a different collection instance with the elements added
    • empty

      <T> @NonNull ImmutableCollection<T> empty()
      Returns an empty collection instance that has the specified element type.
      Type Parameters:
      T - the element type of the returned collection
      Returns:
      an empty collection of the specified element type.
    • filter

      default ImmutableCollection<E> filter(@NonNull Predicate<E> p)
      Retains all elements in this collection that satisfy the specified predicate.
      Parameters:
      p - a predicate
      Returns:
      a collection that only contains elements that satisfy the predicate
    • maxSize

      int maxSize()
      Returns the maximal number of elements that this collection type can hold
      Returns:
      the maximal size
    • remove

      @NonNull ImmutableCollection<E> remove(E element)
      Returns a copy of this collection that contains all elements of this collection except the specified element.
      Parameters:
      element - an element
      Returns:
      this collection instance if it already does not contain the element, or a different collection instance with the element removed
    • removeAll

      Returns a copy of this collection that contains all elements of this collection except the elements of the specified collection.
      Parameters:
      c - a collection with elements to be removed from this collection
      Returns:
      this collection instance if it already does not contain the elements, or a different collection instance with the elements removed
    • retainAll

      Returns a copy of this collection that contains only elements that are in this collection and in the specified collection.
      Parameters:
      c - a collection with elements to be retained in this collection
      Returns:
      this collection instance if it has not changed, or a different collection instance with elements removed
    • toMutable

      @NonNull Collection<E> toMutable()
      Returns a mutable copy of this collection.
      Returns:
      a mutable copy.