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

    Fields inherited from class java.util.AbstractList

    modCount
  • 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
    void add​(int index, E element)  
    boolean add​(E e)  
    boolean addAll​(int index, java.util.Collection<? extends E> c)  
    boolean addAll​(java.util.Collection<? extends E> c)  
    void clear()  
    boolean contains​(java.lang.Object o)  
    boolean containsAll​(java.util.Collection<?> c)  
    boolean equals​(java.lang.Object o)  
    E get​(int index)  
    int hashCode()  
    int indexOf​(java.lang.Object o)  
    boolean isEmpty()  
    java.util.Iterator<E> iterator()  
    int lastIndexOf​(java.lang.Object o)  
    java.util.ListIterator<E> listIterator()  
    java.util.ListIterator<E> listIterator​(int index)  
    E remove​(int index)  
    boolean remove​(java.lang.Object o)  
    boolean removeAll​(java.util.Collection<?> c)  
    boolean retainAll​(java.util.Collection<?> c)  
    E set​(int index, E element)  
    int size()  
    java.lang.Object[] toArray()  
    <T> T[] toArray​(T[] a)  
    java.lang.String toString()  
    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)  

    Methods inherited from class java.util.AbstractList

    removeRange, subList

    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

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface java.util.List

    replaceAll, sort, spliterator
  • Constructor Details

    • IgnorantUnmodifiableList

      public IgnorantUnmodifiableList​(java.util.List<E> original)
    • 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()
      Specified by:
      size in interface java.util.Collection<E>
      Specified by:
      size in interface java.util.List<E>
      Specified by:
      size in class java.util.AbstractCollection<E>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface java.util.Collection<E>
      Specified by:
      isEmpty in interface java.util.List<E>
      Overrides:
      isEmpty in class java.util.AbstractCollection<E>
    • contains

      public boolean contains​(java.lang.Object o)
      Specified by:
      contains in interface java.util.Collection<E>
      Specified by:
      contains in interface java.util.List<E>
      Overrides:
      contains in class java.util.AbstractCollection<E>
    • iterator

      public java.util.Iterator<E> iterator()
      Specified by:
      iterator in interface java.util.Collection<E>
      Specified by:
      iterator in interface java.lang.Iterable<E>
      Specified by:
      iterator in interface java.util.List<E>
      Overrides:
      iterator in class java.util.AbstractList<E>
    • toArray

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

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

      public boolean add​(E e)
      Specified by:
      add in interface java.util.Collection<E>
      Specified by:
      add in interface java.util.List<E>
      Overrides:
      add in class java.util.AbstractList<E>
    • remove

      public boolean remove​(java.lang.Object o)
      Specified by:
      remove in interface java.util.Collection<E>
      Specified by:
      remove in interface java.util.List<E>
      Overrides:
      remove in class java.util.AbstractCollection<E>
    • containsAll

      public boolean containsAll​(java.util.Collection<?> c)
      Specified by:
      containsAll in interface java.util.Collection<E>
      Specified by:
      containsAll in interface java.util.List<E>
      Overrides:
      containsAll in class java.util.AbstractCollection<E>
    • addAll

      public boolean addAll​(java.util.Collection<? extends E> c)
      Specified by:
      addAll in interface java.util.Collection<E>
      Specified by:
      addAll in interface java.util.List<E>
      Overrides:
      addAll in class java.util.AbstractCollection<E>
    • addAll

      public boolean addAll​(int index, java.util.Collection<? extends E> c)
      Specified by:
      addAll in interface java.util.List<E>
      Overrides:
      addAll in class java.util.AbstractList<E>
    • removeAll

      public boolean removeAll​(java.util.Collection<?> c)
      Specified by:
      removeAll in interface java.util.Collection<E>
      Specified by:
      removeAll in interface java.util.List<E>
      Overrides:
      removeAll in class java.util.AbstractCollection<E>
    • retainAll

      public boolean retainAll​(java.util.Collection<?> c)
      Specified by:
      retainAll in interface java.util.Collection<E>
      Specified by:
      retainAll in interface java.util.List<E>
      Overrides:
      retainAll in class java.util.AbstractCollection<E>
    • clear

      public void clear()
      Specified by:
      clear in interface java.util.Collection<E>
      Specified by:
      clear in interface java.util.List<E>
      Overrides:
      clear in class java.util.AbstractList<E>
    • get

      public E get​(int index)
      Specified by:
      get in interface java.util.List<E>
      Specified by:
      get in class java.util.AbstractList<E>
    • set

      public E set​(int index, E element)
      Specified by:
      set in interface java.util.List<E>
      Overrides:
      set in class java.util.AbstractList<E>
    • add

      public void add​(int index, E element)
      Specified by:
      add in interface java.util.List<E>
      Overrides:
      add in class java.util.AbstractList<E>
    • remove

      public E remove​(int index)
      Specified by:
      remove in interface java.util.List<E>
      Overrides:
      remove in class java.util.AbstractList<E>
    • indexOf

      public int indexOf​(java.lang.Object o)
      Specified by:
      indexOf in interface java.util.List<E>
      Overrides:
      indexOf in class java.util.AbstractList<E>
    • lastIndexOf

      public int lastIndexOf​(java.lang.Object o)
      Specified by:
      lastIndexOf in interface java.util.List<E>
      Overrides:
      lastIndexOf in class java.util.AbstractList<E>
    • listIterator

      public java.util.ListIterator<E> listIterator()
      Specified by:
      listIterator in interface java.util.List<E>
      Overrides:
      listIterator in class java.util.AbstractList<E>
    • listIterator

      public java.util.ListIterator<E> listIterator​(int index)
      Specified by:
      listIterator in interface java.util.List<E>
      Overrides:
      listIterator in class java.util.AbstractList<E>
    • equals

      public boolean equals​(java.lang.Object o)
      Specified by:
      equals in interface java.util.Collection<E>
      Specified by:
      equals in interface java.util.List<E>
      Overrides:
      equals in class java.util.AbstractList<E>
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface java.util.Collection<E>
      Specified by:
      hashCode in interface java.util.List<E>
      Overrides:
      hashCode in class java.util.AbstractList<E>
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.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)