Interface ResourceRepository<T>

Type Parameters:
T - the mapped type
All Known Implementing Classes:
ResourceRepositoryImpl

@API(status=STABLE, since="2.0.0-milestone.1.0") public interface ResourceRepository<T>
Represents a view over a ResourceList. The ResourceList contained in this repository is the backing list. The view list is a sorted and filtered version of the backing list. The resources from the backing list are mapped through a ResourceRepositoryMapper when inserted into the view list.
  • Method Details

    • setListener

      void setListener(@Nullable Runnable listener)
      Sets a listener that is called when the view list changes.
      Parameters:
      listener - the listener, can be null
    • setSort

      void setSort(Comparator<T> sort, SortingDirection direction)
      After changing the sort, you still need to call sort().
      Parameters:
      sort - the sort
      direction - the direction
    • setPreventSorting

      boolean setPreventSorting(boolean preventSorting)
      Preventing sorting means that the changes will still arrive at the backing list and view list, but, the view list won't be resorted and if a resource is completely removed, it will stay in the view list until sorting is enabled again. When disabling prevent sorting, you still need to call sort().
      Parameters:
      preventSorting - whether the view should prevent sorting on changes
      Returns:
      whether prevent sorting has changed
    • setFilterAndSort

      Parameters:
      filter - the filter
      Returns:
      the previous filter
    • getAmount

      long getAmount(ResourceKey resource)
      Parameters:
      resource - the resource
      Returns:
      the amount in the view, or zero if not present
    • isSticky

      boolean isSticky(ResourceKey resource)
      Parameters:
      resource - the resource
      Returns:
      whether the resource is sticky
    • sort

      void sort()
      Sorts the view list. Applies sorting and filtering rules.
    • update

      void update(ResourceKey resource, long amount)
      Applies a change to a resource. Will update the backing list, and will also update the view list (depending on if the view is preventing sorting).
      Parameters:
      resource - the resource
      amount - the amount, can be negative or positive, but not zero
    • getViewList

      List<T> getViewList()
      Returns:
      the view list
    • copyBackingList

      MutableResourceList copyBackingList()
      Returns:
      a copy of the backing list
    • clear

      void clear()
      Clears the backing list and view list.