E - data typepublic class ImmutableCollection<E> extends Object implements Collection<E>, Cloneable, Serializable
Collection implementation that doesn't allow any data modifications to be done.
Unlike Collections.unmodifiableCollection(Collection) this implementation keeps collection data copy.
If you need to provide an unmodifiable reference for your collection use Collections implementation.| Modifier and Type | Field and Description |
|---|---|
protected E[] |
data
Collection data. |
| Constructor and Description |
|---|
ImmutableCollection(Collection<? extends E> collection)
Constructs new
ImmutableCollection based on the specified Collection. |
ImmutableCollection(E... data)
Constructs new
ImmutableCollection based on the specified collection data. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E element) |
boolean |
addAll(Collection<? extends E> collection) |
void |
clear() |
boolean |
contains(Object element) |
boolean |
containsAll(Collection<?> collection) |
protected UnsupportedOperationException |
createModificationException()
Returns new
UnsupportedOperationException instance specific for this implementation. |
boolean |
equals(Object o) |
int |
hashCode() |
boolean |
isEmpty() |
Iterator<E> |
iterator() |
boolean |
remove(Object element) |
boolean |
removeAll(Collection<?> collection) |
boolean |
retainAll(Collection<?> collection) |
int |
size() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] array) |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitparallelStream, removeIf, spliterator, stream@NotNull protected final E[] data
Collection data.public ImmutableCollection(@NotNull E... data)
ImmutableCollection based on the specified collection data.data - collection datapublic ImmutableCollection(@NotNull Collection<? extends E> collection)
ImmutableCollection based on the specified Collection.collection - Collectionpublic int size()
size in interface Collection<E>public boolean isEmpty()
isEmpty in interface Collection<E>public boolean contains(@Nullable Object element)
contains in interface Collection<E>@NotNull public Object[] toArray()
toArray in interface Collection<E>@NotNull public <T> T[] toArray(T[] array)
toArray in interface Collection<E>public boolean add(@Nullable E element)
add in interface Collection<E>public boolean remove(@Nullable Object element)
remove in interface Collection<E>public boolean containsAll(@NotNull Collection<?> collection)
containsAll in interface Collection<E>public boolean addAll(@NotNull Collection<? extends E> collection)
addAll in interface Collection<E>public boolean removeAll(@NotNull Collection<?> collection)
removeAll in interface Collection<E>public boolean retainAll(@NotNull Collection<?> collection)
retainAll in interface Collection<E>public void clear()
clear in interface Collection<E>@NotNull protected UnsupportedOperationException createModificationException()
UnsupportedOperationException instance specific for this implementation.UnsupportedOperationException instance specific for this implementationpublic int hashCode()
hashCode in interface Collection<E>hashCode in class Objectpublic boolean equals(@Nullable Object o)
equals in interface Collection<E>equals in class ObjectCopyright © 2020. All rights reserved.