Class AbstractLazyLoadList<E>

  • Type Parameters:
    E - Type of the element of this list
    All Implemented Interfaces:
    java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>
    Direct Known Subclasses:
    AbstractCandidateLazyLoadList

    public abstract class AbstractLazyLoadList<E>
    extends java.lang.Object
    implements java.util.List<E>
    Abstract implementation of a lazy loaded list of (persistent) objects. Needs to be extended to implement the retrieveObjectForIndex() method to retrieve the object at the specified index from whatever datasource is being used, and to implement the getSize() method to return the size of the list. The "datasource" could be results for a query, or a connection to a datastore, or whatever ... just a source of objects. TODO Change Localised message numbers to be generic
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.Integer,​E> itemsByIndex
      Map of object, keyed by the index (0, 1, etc).
      protected int size
      Cached size of the list.
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractLazyLoadList​(java.lang.String cacheType)
      Constructor for a lazy load list.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int index, java.lang.Object element)  
      boolean add​(java.lang.Object e)  
      boolean addAll​(int index, java.util.Collection c)  
      boolean addAll​(java.util.Collection c)  
      void clear()  
      boolean contains​(java.lang.Object o)  
      boolean containsAll​(java.util.Collection c)  
      E get​(int index)  
      protected abstract int getSize()
      Method to return the size of the list.
      int indexOf​(java.lang.Object o)  
      boolean isEmpty()  
      protected boolean isOpen()
      Accessor whether the list is open.
      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)  
      protected abstract E retrieveObjectForIndex​(int index)
      Accessor to retrieve the object at an index.
      E set​(int index, java.lang.Object element)  
      int size()  
      java.util.List<E> subList​(int fromIndex, int toIndex)  
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] a)  
      • 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

        parallelStream, removeIf, stream
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

        equals, hashCode, replaceAll, sort, spliterator
    • Field Detail

      • itemsByIndex

        private java.util.Map<java.lang.Integer,​E> itemsByIndex
        Map of object, keyed by the index (0, 1, etc).
      • size

        protected int size
        Cached size of the list. -1 when not known.
    • Constructor Detail

      • AbstractLazyLoadList

        public AbstractLazyLoadList​(java.lang.String cacheType)
        Constructor for a lazy load list.
        Parameters:
        cacheType - Type of caching of objects in the list
    • Method Detail

      • retrieveObjectForIndex

        protected abstract E retrieveObjectForIndex​(int index)
        Accessor to retrieve the object at an index. Is only called if the object is not currently cached.
        Parameters:
        index - The list index
        Returns:
        The object
      • getSize

        protected abstract int getSize()
        Method to return the size of the list.
        Returns:
        The size
      • isOpen

        protected boolean isOpen()
        Accessor whether the list is open. Always open in this implementation but can be overridden if you want to allow closure.
        Returns:
        Whether it is open.
      • add

        public void add​(int index,
                        java.lang.Object element)
        Specified by:
        add in interface java.util.List<E>
      • add

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

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

        public boolean addAll​(int index,
                              java.util.Collection c)
        Specified by:
        addAll in interface java.util.List<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Specified by:
        clear in interface java.util.List<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>
      • 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>
      • get

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

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

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Specified by:
        isEmpty in interface java.util.List<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>
      • lastIndexOf

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

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

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

        public E remove​(int index)
        Specified by:
        remove in interface java.util.List<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>
      • 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>
      • 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>
      • set

        public E set​(int index,
                     java.lang.Object element)
        Specified by:
        set in interface java.util.List<E>
      • size

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

        public java.util.List<E> subList​(int fromIndex,
                                         int toIndex)
        Specified by:
        subList in interface java.util.List<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>
      • 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>