Class UnmodifiableCollection<E>

  • Type Parameters:
    E - The element type of the collection.
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>
    Direct Known Subclasses:
    UnmodifiableList, UnmodifiableSet, UnmodifiableSortedSet

    public abstract class UnmodifiableCollection<E>
    extends java.lang.Object
    implements java.util.Collection<E>
    Simple unmodifiable collection base class. Note that these are called 'unmodifiable', not 'immutable', as whether they are truly immutable relies on the containing items being immutable classes too. But in that case it is immutable, therefore the Immutable annotations on all it's implementations.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Object[] array  
      protected int length  
      protected int offset  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(E e)  
      boolean addAll​(java.util.Collection<? extends E> collection)  
      UnmodifiableList<E> asList()
      Get the collection as an unmodifiable random access list.
      void clear()  
      boolean contains​(java.lang.Object o)  
      boolean containsAll​(java.util.Collection<?> collection)  
      boolean isEmpty()  
      java.util.Iterator<E> iterator()  
      boolean remove​(java.lang.Object o)  
      boolean removeAll​(java.util.Collection<?> collection)  
      boolean removeIf​(java.util.function.Predicate<? super E> filter)  
      boolean retainAll​(java.util.Collection<?> collection)  
      int size()  
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] ts)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        equals, hashCode, parallelStream, spliterator, stream, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Field Detail

      • array

        protected final transient java.lang.Object[] array
      • length

        protected final transient int length
      • offset

        protected final transient int offset
    • Method Detail

      • asList

        @Nonnull
        public UnmodifiableList<E> asList()
        Get the collection as an unmodifiable random access list.
        Returns:
        The unmodifiable list.
      • toArray

        @Nonnull
        public java.lang.Object[] toArray()
        Specified by:
        toArray in interface java.util.Collection<E>
      • toArray

        @Nonnull
        public <T> T[] toArray​(@Nonnull
                               T[] ts)
        Specified by:
        toArray in interface java.util.Collection<E>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
      • isEmpty

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

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

        @Nonnull
        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
      • containsAll

        public boolean containsAll​(@Nonnull
                                   java.util.Collection<?> collection)
        Specified by:
        containsAll in interface java.util.Collection<E>
      • add

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

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<E>
      • addAll

        public boolean addAll​(@Nonnull
                              java.util.Collection<? extends E> collection)
        Specified by:
        addAll in interface java.util.Collection<E>
      • removeAll

        public boolean removeAll​(@Nonnull
                                 java.util.Collection<?> collection)
        Specified by:
        removeAll in interface java.util.Collection<E>
      • removeIf

        public boolean removeIf​(@Nonnull
                                java.util.function.Predicate<? super E> filter)
        Specified by:
        removeIf in interface java.util.Collection<E>
      • retainAll

        public boolean retainAll​(@Nonnull
                                 java.util.Collection<?> collection)
        Specified by:
        retainAll in interface java.util.Collection<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>