Package com.google.common.collect
Class ImmutableCollection<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- com.google.common.collect.ImmutableCollection<E>
-
- All Implemented Interfaces:
Serializable,Iterable<E>,Collection<E>
- Direct Known Subclasses:
ImmutableList,ImmutableMultiset,ImmutableSet
@GwtCompatible(emulated=true) public abstract class ImmutableCollection<E> extends AbstractCollection<E> implements Serializable
An immutable collection. Does not permit null elements.In addition to the
Collectionmethods, this class has anasList()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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classImmutableCollection.Builder<E>Abstract base class for builders ofImmutableCollectiontypes.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleanadd(E e)Deprecated.Unsupported operation.booleanaddAll(Collection<? extends E> newElements)Deprecated.Unsupported operation.ImmutableList<E>asList()Returns a list view of the collection.voidclear()Deprecated.Unsupported operation.booleancontains(Object object)abstract UnmodifiableIterator<E>iterator()Returns an unmodifiable iterator across the elements in this collection.booleanremove(Object object)Deprecated.Unsupported operation.booleanremoveAll(Collection<?> oldElements)Deprecated.Unsupported operation.booleanretainAll(Collection<?> elementsToKeep)Deprecated.Unsupported operation.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
-
-
-
-
Method Detail
-
iterator
public abstract UnmodifiableIterator<E> iterator()
Returns an unmodifiable iterator across the elements in this collection.- Specified by:
iteratorin interfaceCollection<E>- Specified by:
iteratorin interfaceIterable<E>- Specified by:
iteratorin classAbstractCollection<E>
-
toArray
public final Object[] toArray()
- Specified by:
toArrayin interfaceCollection<E>- Overrides:
toArrayin classAbstractCollection<E>
-
toArray
public final <T> T[] toArray(T[] other)
- Specified by:
toArrayin interfaceCollection<E>- Overrides:
toArrayin classAbstractCollection<E>
-
contains
public boolean contains(@Nullable Object object)
- Specified by:
containsin interfaceCollection<E>- Overrides:
containsin classAbstractCollection<E>
-
add
@Deprecated public final boolean add(E e)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
addin interfaceCollection<E>- Overrides:
addin classAbstractCollection<E>- Throws:
UnsupportedOperationException- always
-
remove
@Deprecated public final boolean remove(Object object)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
removein interfaceCollection<E>- Overrides:
removein classAbstractCollection<E>- Throws:
UnsupportedOperationException- always
-
addAll
@Deprecated public final boolean addAll(Collection<? extends E> newElements)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
addAllin interfaceCollection<E>- Overrides:
addAllin classAbstractCollection<E>- Throws:
UnsupportedOperationException- always
-
removeAll
@Deprecated public final boolean removeAll(Collection<?> oldElements)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
removeAllin interfaceCollection<E>- Overrides:
removeAllin classAbstractCollection<E>- Throws:
UnsupportedOperationException- always
-
retainAll
@Deprecated public final boolean retainAll(Collection<?> elementsToKeep)
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
retainAllin interfaceCollection<E>- Overrides:
retainAllin classAbstractCollection<E>- Throws:
UnsupportedOperationException- always
-
clear
@Deprecated public final void clear()
Deprecated.Unsupported operation.Guaranteed to throw an exception and leave the collection unmodified.- Specified by:
clearin interfaceCollection<E>- Overrides:
clearin classAbstractCollection<E>- Throws:
UnsupportedOperationException- always
-
asList
public ImmutableList<E> asList()
Returns a list view of the collection.- Since:
- 2.0
-
-