Class LazyList<E>

  • Type Parameters:
    E - Entity type.
    All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>

    public class LazyList<E>
    extends java.lang.Object
    implements java.util.List<E>, java.io.Closeable
    A thread-safe, unmodifiable list that reads entities once they are accessed from an underlying database cursor. Make sure to close the list once you are done with it. The lazy list can be cached or not. Cached lazy lists store the entities in memory to avoid loading entities more than once. Some features of the list are limited to cached lists (e.g. features that require the entire list). Cached lists close the cursor automatically once you queried all entities. However, to avoid leaked cursors, you should not rely on this behavior: if an exception occurs before the entire list is read, you should close the lazy list (and thus the underlying cursor) on your own to be on the safe side.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  LazyList.LazyIterator  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int location, E object)  
      boolean add​(E object)  
      boolean addAll​(int arg0, java.util.Collection<? extends E> arg1)  
      boolean addAll​(java.util.Collection<? extends E> arg0)  
      protected void checkCached()  
      void clear()  
      void close()  
      boolean contains​(java.lang.Object object)  
      boolean containsAll​(java.util.Collection<?> collection)  
      E get​(int location)  
      int getLoadedCount()  
      int indexOf​(java.lang.Object object)  
      boolean isClosed()  
      boolean isEmpty()  
      boolean isLoadedCompletely()  
      java.util.Iterator<E> iterator()  
      int lastIndexOf​(java.lang.Object object)  
      CloseableListIterator<E> listIterator()  
      java.util.ListIterator<E> listIterator​(int location)  
      CloseableListIterator<E> listIteratorAutoClose()
      Closes this list's cursor once the iterator is fully iterated through.
      protected E loadEntity​(int location)
      Lock must be locked when entering this method.
      void loadRemaining()
      Loads the remaining entities (if any) that were not loaded before.
      E peek​(int location)
      Like get but does not load the entity if it was not loaded before.
      E remove​(int location)  
      boolean remove​(java.lang.Object object)  
      boolean removeAll​(java.util.Collection<?> arg0)  
      boolean retainAll​(java.util.Collection<?> arg0)  
      E set​(int location, E object)  
      int size()  
      java.util.List<E> subList​(int start, int end)  
      java.lang.Object[] toArray()  
      <T> T[] toArray​(T[] array)  
      • 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, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
      • Methods inherited from interface java.util.List

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

      • loadRemaining

        public void loadRemaining()
        Loads the remaining entities (if any) that were not loaded before. Applies to cached lazy lists only.
      • checkCached

        protected void checkCached()
      • peek

        public E peek​(int location)
        Like get but does not load the entity if it was not loaded before.
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
      • isClosed

        public boolean isClosed()
      • getLoadedCount

        public int getLoadedCount()
      • isLoadedCompletely

        public boolean isLoadedCompletely()
      • add

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

        public void add​(int location,
                        E object)
        Specified by:
        add in interface java.util.List<E>
      • addAll

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

        public boolean addAll​(int arg0,
                              java.util.Collection<? extends E> arg1)
        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 object)
        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<?> collection)
        Specified by:
        containsAll in interface java.util.Collection<E>
        Specified by:
        containsAll in interface java.util.List<E>
      • get

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

        protected E loadEntity​(int location)
        Lock must be locked when entering this method.
      • indexOf

        public int indexOf​(java.lang.Object object)
        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 object)
        Specified by:
        lastIndexOf in interface java.util.List<E>
      • listIterator

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

        public CloseableListIterator<E> listIteratorAutoClose()
        Closes this list's cursor once the iterator is fully iterated through.
      • listIterator

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

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

        public boolean remove​(java.lang.Object object)
        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<?> arg0)
        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<?> arg0)
        Specified by:
        retainAll in interface java.util.Collection<E>
        Specified by:
        retainAll in interface java.util.List<E>
      • set

        public E set​(int location,
                     E object)
        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 start,
                                         int end)
        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[] array)
        Specified by:
        toArray in interface java.util.Collection<E>
        Specified by:
        toArray in interface java.util.List<E>