Class BlockList<T>

  • Type Parameters:
    T - type of list element.
    All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>

    public class BlockList<T>
    extends java.util.AbstractList<T>
    Random access list that allocates entries in blocks.

    Unlike ArrayList, this type does not need to reallocate the internal array in order to expand the capacity of the list. Access to any element is constant time, but requires two array lookups instead of one.

    To handle common usages, add(Object) and iterator() use internal code paths to amortize out the second array lookup, making addition and simple iteration closer to one array operation per element processed.

    Similar to ArrayList, adding or removing from any position except the end of the list requires O(N) time to copy all elements between the modification point and the end of the list. Applications are strongly encouraged to not use this access pattern with this list implementation.

    • Field Summary

      • Fields inherited from class java.util.AbstractList

        modCount
    • Constructor Summary

      Constructors 
      Constructor Description
      BlockList()
      Initialize an empty list.
      BlockList​(int capacity)
      Initialize an empty list with an expected capacity.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int index, T element)  
      boolean add​(T element)  
      void addAll​(BlockList<T> src)
      Quickly append all elements of another BlockList.
      void addAll​(T[] src, int srcIdx, int srcCnt)
      Quickly append all elements from an array.
      void clear()  
      T get​(int index)  
      java.util.Iterator<T> iterator()  
      T remove​(int index)  
      T set​(int index, T element)  
      int size()  
      • Methods inherited from class java.util.AbstractList

        addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, listIterator, removeRange, subList
      • Methods inherited from class java.util.AbstractCollection

        addAll, contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
      • 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

        addAll, contains, containsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
    • Constructor Detail

      • BlockList

        public BlockList()
        Initialize an empty list.
      • BlockList

        public BlockList​(int capacity)
        Initialize an empty list with an expected capacity.
        Parameters:
        capacity - number of elements expected to be in the list.
    • Method Detail

      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in interface java.util.List<T>
        Specified by:
        size in class java.util.AbstractCollection<T>
      • clear

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

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

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

        public void addAll​(BlockList<T> src)
        Quickly append all elements of another BlockList.
        Parameters:
        src - the list to copy elements from.
      • addAll

        public void addAll​(T[] src,
                           int srcIdx,
                           int srcCnt)
        Quickly append all elements from an array.
        Parameters:
        src - the source array.
        srcIdx - first index to copy.
        srcCnt - number of elements to copy.
      • add

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

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

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

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