Package org.jibx.util

Class LazyList

All Implemented Interfaces:
Iterable, Collection, List, SequencedCollection

public class LazyList extends AbstractList
List implementation with lazy array construction and modification tracking. The lazy array construction is a minor optimization, to save the added overhead of a backing array for lists which are frequently empty. The modification tracking feature supports filtered list construction with result caching.
Author:
Dennis M. Sosnoski
  • Field Details

    • EMPTY_ITERATOR

      public static final Iterator EMPTY_ITERATOR
      Singleton iterator for empty collection.
    • EMPTY_LIST

      public static final LazyList EMPTY_LIST
      Unmodifiable empty list instance.
    • m_size

      private int m_size
      Number of items currently present in list.
    • m_limit

      private int m_limit
      Maximum number of items allowed before resizing.
    • m_array

      private Object[] m_array
      Backing array (lazy instantiation, null if not used).
  • Constructor Details

    • LazyList

      public LazyList()
  • Method Details

    • makeSpace

      private void makeSpace(int count)
      Make sure space is available for adding to the list. This grows the size of the backing array, if necessary.
      Parameters:
      count -
    • get

      public Object get(int index)
      Specified by:
      get in interface List
      Specified by:
      get in class AbstractList
    • size

      public int size()
      Specified by:
      size in interface Collection
      Specified by:
      size in interface List
      Specified by:
      size in class AbstractCollection
    • add

      public void add(int index, Object element)
      Specified by:
      add in interface List
      Overrides:
      add in class AbstractList
    • iterator

      public Iterator iterator()
      Specified by:
      iterator in interface Collection
      Specified by:
      iterator in interface Iterable
      Specified by:
      iterator in interface List
      Overrides:
      iterator in class AbstractList
    • remove

      public Object remove(int index)
      Specified by:
      remove in interface List
      Overrides:
      remove in class AbstractList
    • set

      public Object set(int index, Object element)
      Specified by:
      set in interface List
      Overrides:
      set in class AbstractList
    • removeRange

      protected void removeRange(int from, int to)
      Overrides:
      removeRange in class AbstractList
    • getModCount

      public int getModCount()
      Get modify counter. This supports tracking changes to determine when cached filters need to be updated.
      Returns:
      count
    • remove

      public void remove(int from, int to)
      Remove range of values. This is just a public version of the protected base class method removeRange(int, int)
      Parameters:
      from -
      to -
    • compact

      public void compact()
      Compact the list, removing any null values.