Class LazyList<E>

java.lang.Object
io.objectbox.query.LazyList<E>
Type Parameters:
E - Object type (entity).
All Implemented Interfaces:
Iterable<E>, Collection<E>, List<E>

public class LazyList<E> extends Object implements List<E>
A thread-safe, unmodifiable List that gets Objects from their Box not until they are accessed. Internally the list is backed by an array of Object IDs.

If the list is set to not cache retrieved Objects, each operation will get the latest version of an Object from its Box. However, in this mode only a limited set of List operations, like get or iterator are supported.

If the list is set to cache retrieved Objects, operations will return a previously fetched version of an Object, which might not equal the latest version in its Box. However, in this mode almost all List operations are supported. Note that operations that require the whole list, like contains, will fetch all Objects in this list from the Box at once.

Note: as Objects are fetched on demand, this list returns a null Object if the Object was removed from its Box after this list was created.

  • Method Details

    • 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.
    • getLoadedCount

      public int getLoadedCount()
    • isLoadedCompletely

      public boolean isLoadedCompletely()
    • add

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

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

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

      public boolean addAll(int arg0, Collection<? extends E> arg1)
      Specified by:
      addAll in interface List<E>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface List<E>
    • contains

      public boolean contains(Object object)
      Specified by:
      contains in interface Collection<E>
      Specified by:
      contains in interface List<E>
    • containsAll

      public boolean containsAll(Collection<?> collection)
      Specified by:
      containsAll in interface Collection<E>
      Specified by:
      containsAll in interface List<E>
    • get

      @Nullable public E get(int location)
      Gets and returns the Object at the specified position in this list from its Box. Returns null if the Object was removed from its Box. If this list is caching retrieved Objects, returns the previously fetched version.
      Specified by:
      get in interface List<E>
    • indexOf

      public int indexOf(Object object)
      Specified by:
      indexOf in interface List<E>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<E>
      Specified by:
      isEmpty in interface List<E>
    • iterator

      public Iterator<E> iterator()
      Specified by:
      iterator in interface Collection<E>
      Specified by:
      iterator in interface Iterable<E>
      Specified by:
      iterator in interface List<E>
    • lastIndexOf

      public int lastIndexOf(Object object)
      Specified by:
      lastIndexOf in interface List<E>
    • listIterator

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

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

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

      public boolean remove(Object object)
      Specified by:
      remove in interface Collection<E>
      Specified by:
      remove in interface List<E>
    • removeAll

      public boolean removeAll(Collection<?> arg0)
      Specified by:
      removeAll in interface Collection<E>
      Specified by:
      removeAll in interface List<E>
    • retainAll

      public boolean retainAll(Collection<?> arg0)
      Specified by:
      retainAll in interface Collection<E>
      Specified by:
      retainAll in interface List<E>
    • set

      public E set(int location, E object)
      Specified by:
      set in interface List<E>
    • size

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

      public List<E> subList(int start, int end)
      Specified by:
      subList in interface List<E>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface List<E>
    • toArray

      public <T> T[] toArray(T[] array)
      Specified by:
      toArray in interface Collection<E>
      Specified by:
      toArray in interface List<E>