Package de.tum.in.test.api.util
Class IgnorantUnmodifiableList<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
de.tum.in.test.api.util.IgnorantUnmodifiableList<E>
- Type Parameters:
E- Type of the elements in the List.
- All Implemented Interfaces:
java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>,java.util.RandomAccess
@API(status=INTERNAL)
public final class IgnorantUnmodifiableList<E>
extends java.util.AbstractList<E>
implements java.util.RandomAccess
This is a proxy for Lists to prevent modification silently.
While the lists obtained from List.copyOf(Collection) or
Collections.unmodifiableList(List) throw
UnsupportedOperationExceptions on method calls that would change
the lists state, this class will intentionally not do this.
It is however possible to supply an IgnorantUnmodifiableList
with a BiConsumer that gets supplied with the signature of the
called method and, if present, the (most important) argument passed to the
method.
Please note that this class was created for security reasons to prevent
modifications without causing exceptions. For creating regular unmodifiable
lists, List.copyOf(Collection) or
Collections.unmodifiableList(List) should always be preferred.
- Author:
- Christian Femers
- See Also:
List.of(Object...),List.copyOf(Collection),Collections.unmodifiableList(List)
-
Field Summary
-
Constructor Summary
Constructors Constructor Description IgnorantUnmodifiableList(java.util.List<E> original)IgnorantUnmodifiableList(java.util.List<E> original, java.util.function.BiConsumer<java.lang.String,java.lang.Object> onModification) -
Method Summary
Modifier and Type Method Description voidadd(int index, E element)booleanadd(E e)booleanaddAll(int index, java.util.Collection<? extends E> c)booleanaddAll(java.util.Collection<? extends E> c)voidclear()booleancontains(java.lang.Object o)booleancontainsAll(java.util.Collection<?> c)booleanequals(java.lang.Object o)Eget(int index)inthashCode()intindexOf(java.lang.Object o)booleanisEmpty()java.util.Iterator<E>iterator()intlastIndexOf(java.lang.Object o)java.util.ListIterator<E>listIterator()java.util.ListIterator<E>listIterator(int index)Eremove(int index)booleanremove(java.lang.Object o)booleanremoveAll(java.util.Collection<?> c)booleanretainAll(java.util.Collection<?> c)Eset(int index, E element)intsize()java.lang.Object[]toArray()<T> T[]toArray(T[] a)java.lang.StringtoString()static <E> java.util.List<E>wrap(java.util.List<E> original)static <E> java.util.List<E>wrapWith(java.util.List<E> original, java.util.function.BiConsumer<java.lang.String,java.lang.Object> onModification)
-
Constructor Details
-
IgnorantUnmodifiableList
-
IgnorantUnmodifiableList
public IgnorantUnmodifiableList(java.util.List<E> original, java.util.function.BiConsumer<java.lang.String,java.lang.Object> onModification)
-
-
Method Details
-
size
public int size() -
isEmpty
public boolean isEmpty() -
contains
public boolean contains(java.lang.Object o) -
iterator
-
toArray
public java.lang.Object[] toArray() -
toArray
public <T> T[] toArray(T[] a) -
add
-
remove
public boolean remove(java.lang.Object o) -
containsAll
public boolean containsAll(java.util.Collection<?> c) -
addAll
-
addAll
-
removeAll
public boolean removeAll(java.util.Collection<?> c) -
retainAll
public boolean retainAll(java.util.Collection<?> c) -
clear
public void clear() -
get
-
set
-
add
-
remove
-
indexOf
public int indexOf(java.lang.Object o) -
lastIndexOf
public int lastIndexOf(java.lang.Object o) -
listIterator
-
listIterator
-
equals
public boolean equals(java.lang.Object o) -
hashCode
public int hashCode() -
toString
public java.lang.String toString()- Overrides:
toStringin classjava.util.AbstractCollection<E>
-
wrap
public static <E> java.util.List<E> wrap(java.util.List<E> original) -
wrapWith
public static <E> java.util.List<E> wrapWith(java.util.List<E> original, java.util.function.BiConsumer<java.lang.String,java.lang.Object> onModification)
-