Class ImmutableCollection<E>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>
    Direct Known Subclasses:
    ImmutableList, ImmutableMultiset, ImmutableSet

    @GwtCompatible(emulated=true)
    public abstract class ImmutableCollection<E>
    extends java.util.AbstractCollection<E>
    implements java.io.Serializable
    An immutable collection. Does not permit null elements.

    In addition to the Collection methods, this class has an asList() method, which returns a list view of the collection's elements.

    Note: Although this class is not final, it cannot be subclassed outside of this package as it has no public or protected constructors. Thus, instances of this type are guaranteed to be immutable.

    Since:
    2.0 (imported from Google Collections Library)
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      boolean add​(E e)
      Deprecated.
      Unsupported operation.
      boolean addAll​(java.util.Collection<? extends E> newElements)
      Deprecated.
      Unsupported operation.
      ImmutableList<E> asList()
      Returns a list view of the collection.
      void clear()
      Deprecated.
      Unsupported operation.
      boolean contains​(java.lang.Object object)  
      abstract UnmodifiableIterator<E> iterator()
      Returns an unmodifiable iterator across the elements in this collection.
      boolean remove​(java.lang.Object object)
      Deprecated.
      Unsupported operation.
      boolean removeAll​(java.util.Collection<?> oldElements)
      Deprecated.
      Unsupported operation.
      boolean retainAll​(java.util.Collection<?> elementsToKeep)
      Deprecated.
      Unsupported operation.
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] other)  
      • Methods inherited from class java.util.AbstractCollection

        containsAll, isEmpty, size, toString
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Method Detail

      • iterator

        public abstract UnmodifiableIterator<E> iterator()
        Returns an unmodifiable iterator across the elements in this collection.
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
      • toArray

        public final java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<E>
        Overrides:
        toArray in class java.util.AbstractCollection<E>
      • toArray

        public final <T> T[] toArray​(T[] other)
        Specified by:
        toArray in interface java.util.Collection<E>
        Overrides:
        toArray in class java.util.AbstractCollection<E>
      • contains

        public boolean contains​(@Nullable
                                java.lang.Object object)
        Specified by:
        contains in interface java.util.Collection<E>
        Overrides:
        contains in class java.util.AbstractCollection<E>
      • add

        @Deprecated
        public final boolean add​(E e)
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Specified by:
        add in interface java.util.Collection<E>
        Overrides:
        add in class java.util.AbstractCollection<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • remove

        @Deprecated
        public final boolean remove​(java.lang.Object object)
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Specified by:
        remove in interface java.util.Collection<E>
        Overrides:
        remove in class java.util.AbstractCollection<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • addAll

        @Deprecated
        public final boolean addAll​(java.util.Collection<? extends E> newElements)
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Specified by:
        addAll in interface java.util.Collection<E>
        Overrides:
        addAll in class java.util.AbstractCollection<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • removeAll

        @Deprecated
        public final boolean removeAll​(java.util.Collection<?> oldElements)
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Specified by:
        removeAll in interface java.util.Collection<E>
        Overrides:
        removeAll in class java.util.AbstractCollection<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • retainAll

        @Deprecated
        public final boolean retainAll​(java.util.Collection<?> elementsToKeep)
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Specified by:
        retainAll in interface java.util.Collection<E>
        Overrides:
        retainAll in class java.util.AbstractCollection<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • clear

        @Deprecated
        public final void clear()
        Deprecated.
        Unsupported operation.
        Guaranteed to throw an exception and leave the collection unmodified.
        Specified by:
        clear in interface java.util.Collection<E>
        Overrides:
        clear in class java.util.AbstractCollection<E>
        Throws:
        java.lang.UnsupportedOperationException - always
      • asList

        public ImmutableList<E> asList()
        Returns a list view of the collection.
        Since:
        2.0