Package eu.simuline.util
Class CollectionsExt.ImmutableList<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- eu.simuline.util.CollectionsExt.AbstractImmutableCollection<List<E>,E>
-
- eu.simuline.util.CollectionsExt.ImmutableList<E>
-
- Type Parameters:
E- the class of the elements of this list.
- All Implemented Interfaces:
Iterable<E>,Collection<E>,List<E>
- Enclosing class:
- CollectionsExt<E>
public static final class CollectionsExt.ImmutableList<E> extends CollectionsExt.AbstractImmutableCollection<List<E>,E> implements List<E>
A list which prevents being modified by throwing an exception for the modifying methods.
-
-
Constructor Summary
Constructors Constructor Description ImmutableList(List<E> list)ImmutableList(Set<CollectionsExt.Modification> mods, List<E> list)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E obj)booleanaddAll(int index, Collection<? extends E> coll)booleanequals(Object obj)Eget(int index)inthashCode()intindexOf(Object obj)intlastIndexOf(Object obj)ListIterator<E>listIterator()ListIterator<E>listIterator(int index)Eremove(int index)voidreplaceAll(UnaryOperator<E> operator)Eset(int index, E element)voidsort(Comparator<? super E> cmp)List<E>subList(int fromIndex, int toIndex)List<E>unrestricted()Returns the underlying set without the restrictions imposed by thisCollectionsExt.ImmutableCollection.-
Methods inherited from class eu.simuline.util.CollectionsExt.AbstractImmutableCollection
add, addAll, allowedModifications, allowModification, allowModifications, clear, iterator, remove, removeAll, removeIf, retainAll, size, toString
-
Methods inherited from class java.util.AbstractCollection
contains, containsAll, isEmpty, toArray, toArray
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
-
-
-
Method Detail
-
unrestricted
public List<E> unrestricted()
Description copied from class:CollectionsExt.AbstractImmutableCollectionReturns the underlying set without the restrictions imposed by thisCollectionsExt.ImmutableCollection. Note that the result may still throwUnsupportedOperationExceptions depending on the implementation.- Specified by:
unrestrictedin classCollectionsExt.AbstractImmutableCollection<List<E>,E>
-
add
public void add(int index, E obj)- Specified by:
addin interfaceList<E>- Throws:
UnsupportedOperationException- if eitherunrestricted()does not allow this operation orAddObjis no allowed operation according toCollectionsExt.AbstractImmutableCollection.allowedModifications().
-
addAll
public boolean addAll(int index, Collection<? extends E> coll)- Specified by:
addAllin interfaceList<E>- Throws:
UnsupportedOperationException- if eitherunrestricted()does not allow this operation orAddObjis no allowed operation according toCollectionsExt.AbstractImmutableCollection.allowedModifications(). In the latter case it does not matter, whether effectively it is tried to add objects which is the case onlycollis not empty.
-
hashCode
public int hashCode()
-
equals
public boolean equals(Object obj)
-
lastIndexOf
public int lastIndexOf(Object obj)
- Specified by:
lastIndexOfin interfaceList<E>
-
listIterator
public ListIterator<E> listIterator()
- Specified by:
listIteratorin interfaceList<E>
-
listIterator
public ListIterator<E> listIterator(int index)
- Specified by:
listIteratorin interfaceList<E>
-
remove
public E remove(int index)
- Specified by:
removein interfaceList<E>- Throws:
UnsupportedOperationException- if eitherunrestricted()does not allow this operation orRemoveObjis no allowed operation according toCollectionsExt.AbstractImmutableCollection.allowedModifications().
-
set
public E set(int index, E element)
- Specified by:
setin interfaceList<E>- Throws:
UnsupportedOperationException- if eitherunrestricted()does not allow this operation orSetObjis no allowed operation according toCollectionsExt.AbstractImmutableCollection.allowedModifications(). In the latter case it does not matter, whether effectively it is tried to set an object which is the case only ifelementis not at placeindexinthis.
-
replaceAll
public void replaceAll(UnaryOperator<E> operator)
- Specified by:
replaceAllin interfaceList<E>- Throws:
UnsupportedOperationException- if eitherunrestricted()does not allow this operation orSetObjis no allowed operation according toCollectionsExt.AbstractImmutableCollection.allowedModifications(). In the latter case it does not matter, whether effectively it is tried to replace an object which is the case only ifoperatorreally changes an object.
-
sort
public void sort(Comparator<? super E> cmp)
- Specified by:
sortin interfaceList<E>- Throws:
UnsupportedOperationException- if eitherunrestricted()does not allow this operation orSetObjis no allowed operation according toCollectionsExt.AbstractImmutableCollection.allowedModifications(). In the latter case it does not matter, whether effectively it is tried to replace an object which is the case only ifthisis not completely sorted according tocmp. This definition is in conjunction with the requirement, ofList.sort(Comparator)that this exception is thrown iff the list iterator does not permit theListIterator.set(Object)method.
-
-