Class QueryResultList<T>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<T>
org.minimalj.repository.list.QueryResultList<T>
Type Parameters:
T - Class of the Elements
All Implemented Interfaces:
java.io.Serializable, java.lang.Iterable<T>, java.util.Collection<T>, java.util.List<T>, Sortable

public class QueryResultList<T>
extends java.util.AbstractList<T>
implements Sortable, java.io.Serializable
A repository may (but is not required to) return a QueryResultList when the find method is called. Only the size of the list is calculated when a QueryResultList is calculated. Every element read with a get(index) is loaded from the backend.

If you know you will use many elements of the List use the subList method to load a complete range of elements in a unmodifiable List. This is how such lists are used by the Frontend

A QueryResultList is unmodifiable. Every call of a add or remove method will result in a UnsupportedOperationException.

If the database has changed before you call a get or subList method you may get null as element or a unexpected reduced sub list. You don't get an exception in that cases.

QueryResultList is Sortable. The order of the elements can be changed at any time. The size of the List is not recalculated and the sub List created before a sort are not updated. Of course this is mainly used by a Frontend. Business methods should execute a new find on the Repository / Backend.

See Also:
Serialized Form
  • Field Summary

    Fields inherited from class java.util.AbstractList

    modCount
  • Constructor Summary

    Constructors 
    Constructor Description
    QueryResultList​(Repository repository, java.lang.Class<T> clazz, Query query)  
  • Method Summary

    Modifier and Type Method Description
    boolean canSortBy​(java.lang.Object sortKey)  
    T get​(int index)  
    int size()  
    void sort​(java.lang.Object[] sortKeys, boolean[] sortDirections)  
    java.util.List<T> subList​(int fromIndex, int toIndex)  

    Methods inherited from class java.util.AbstractList

    add, add, addAll, clear, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, remove, removeRange, set

    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 Details

  • Method Details

    • get

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

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

      public void sort​(java.lang.Object[] sortKeys, boolean[] sortDirections)
      Specified by:
      sort in interface Sortable
    • canSortBy

      public boolean canSortBy​(java.lang.Object sortKey)
      Specified by:
      canSortBy in interface Sortable