Class EmptyArrayList

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Iterable, java.util.Collection, java.util.List, java.util.RandomAccess

    public class EmptyArrayList
    extends java.util.ArrayList
    Unmodifiable empty array list. This defines a singleton instance of itself, which can then be used whereever an empty list is convenient. This class is required to support methods which return instances of java.util.ArrayList in order to guarantee random access to the returned list in constant time as part of the method contract. java.util.Collection.EMPTY_LIST is not an instance of java.util.ArrayList, so it cannot be used.
    Author:
    Dennis M. Sosnoski
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static EmptyArrayList INSTANCE  
      • Fields inherited from class java.util.AbstractList

        modCount
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private EmptyArrayList()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int index, java.lang.Object element)  
      boolean add​(java.lang.Object o)  
      boolean addAll​(int index, java.util.Collection c)  
      boolean addAll​(java.util.Collection c)  
      void clear()  
      void ensureCapacity​(int minCapacity)  
      java.lang.Object remove​(int index)  
      boolean remove​(java.lang.Object o)  
      boolean removeAll​(java.util.Collection c)  
      protected void removeRange​(int fromIndex, int toIndex)  
      boolean retainAll​(java.util.Collection c)  
      java.lang.Object set​(int index, java.lang.Object element)  
      void trimToSize()  
      • Methods inherited from class java.util.ArrayList

        clone, contains, equals, forEach, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeIf, replaceAll, size, sort, spliterator, subList, toArray, toArray
      • Methods inherited from class java.util.AbstractCollection

        containsAll, toString
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        parallelStream, stream, toArray
      • Methods inherited from interface java.util.List

        containsAll
    • Constructor Detail

      • EmptyArrayList

        private EmptyArrayList()
    • Method Detail

      • add

        public void add​(int index,
                        java.lang.Object element)
        Specified by:
        add in interface java.util.List
        Overrides:
        add in class java.util.ArrayList
      • add

        public boolean add​(java.lang.Object o)
        Specified by:
        add in interface java.util.Collection
        Specified by:
        add in interface java.util.List
        Overrides:
        add in class java.util.ArrayList
      • addAll

        public boolean addAll​(java.util.Collection c)
        Specified by:
        addAll in interface java.util.Collection
        Specified by:
        addAll in interface java.util.List
        Overrides:
        addAll in class java.util.ArrayList
      • addAll

        public boolean addAll​(int index,
                              java.util.Collection c)
        Specified by:
        addAll in interface java.util.List
        Overrides:
        addAll in class java.util.ArrayList
      • ensureCapacity

        public void ensureCapacity​(int minCapacity)
        Overrides:
        ensureCapacity in class java.util.ArrayList
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection
        Specified by:
        clear in interface java.util.List
        Overrides:
        clear in class java.util.ArrayList
      • remove

        public java.lang.Object remove​(int index)
        Specified by:
        remove in interface java.util.List
        Overrides:
        remove in class java.util.ArrayList
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection
        Specified by:
        remove in interface java.util.List
        Overrides:
        remove in class java.util.ArrayList
      • removeRange

        protected void removeRange​(int fromIndex,
                                   int toIndex)
        Overrides:
        removeRange in class java.util.ArrayList
      • set

        public java.lang.Object set​(int index,
                                    java.lang.Object element)
        Specified by:
        set in interface java.util.List
        Overrides:
        set in class java.util.ArrayList
      • trimToSize

        public void trimToSize()
        Overrides:
        trimToSize in class java.util.ArrayList
      • removeAll

        public boolean removeAll​(java.util.Collection c)
        Specified by:
        removeAll in interface java.util.Collection
        Specified by:
        removeAll in interface java.util.List
        Overrides:
        removeAll in class java.util.ArrayList
      • retainAll

        public boolean retainAll​(java.util.Collection c)
        Specified by:
        retainAll in interface java.util.Collection
        Specified by:
        retainAll in interface java.util.List
        Overrides:
        retainAll in class java.util.ArrayList