Class GridViewImpl

java.lang.Object
com.refinedmods.refinedstorage.api.grid.view.GridViewImpl
All Implemented Interfaces:
GridView

@API(status=STABLE, since="2.0.0-milestone.1.0") public class GridViewImpl extends Object implements GridView
  • Constructor Details

    • GridViewImpl

      public GridViewImpl(GridResourceFactory resourceFactory, ResourceList backingList, Map<ResourceKey,TrackedResource> initialTrackedResources, GridSortingType identitySortingType, GridSortingType defaultSortingType)
      Parameters:
      resourceFactory - a factory that transforms a resource amount to a grid resource
      backingList - the backing list
      initialTrackedResources - initial tracked resources state
      identitySortingType - a sorting type required to keep a consistent sorting order with quantity sorting
      defaultSortingType - the default sorting type
  • Method Details

    • setListener

      public void setListener(@Nullable Runnable listener)
      Description copied from interface: GridView
      Sets a listener that is called when the grid view changes.
      Specified by:
      setListener in interface GridView
      Parameters:
      listener - the listener, can be null
    • setSortingType

      public void setSortingType(GridSortingType sortingType)
      Description copied from interface: GridView
      Changing the sorting type still requires a call to GridView.sort().
      Specified by:
      setSortingType in interface GridView
      Parameters:
      sortingType - the sorting type
    • setFilterAndSort

      public BiPredicate<GridView,GridResource> setFilterAndSort(BiPredicate<GridView,GridResource> predicate)
      Specified by:
      setFilterAndSort in interface GridView
      Parameters:
      predicate - the filter
      Returns:
      the previous filtering predicate
    • setPreventSorting

      public boolean setPreventSorting(boolean changedPreventSorting)
      Description copied from interface: GridView
      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 zeroed, will stay in view until sorting is enabled again. This still requires a call to GridView.sort() when preventing sorting is disabled again.
      Specified by:
      setPreventSorting in interface GridView
      Parameters:
      changedPreventSorting - whether the view should prevent sorting on changes
      Returns:
      whether prevent sorting has changed
    • setSortingDirection

      public void setSortingDirection(GridSortingDirection sortingDirection)
      Description copied from interface: GridView
      Changing the sorting direction still requires a call to GridView.sort().
      Specified by:
      setSortingDirection in interface GridView
      Parameters:
      sortingDirection - the sorting direction
    • getTrackedResource

      public Optional<TrackedResource> getTrackedResource(ResourceKey resource)
      Specified by:
      getTrackedResource in interface GridView
      Parameters:
      resource - the resource
      Returns:
      the tracked resource, if present
    • getAmount

      public long getAmount(ResourceKey resource)
      Specified by:
      getAmount in interface GridView
      Parameters:
      resource - the resource
      Returns:
      the amount in the view, or zero if not present
    • sort

      public void sort()
      Description copied from interface: GridView
      Sorts the view list. Applies sorting and filtering rules.
      Specified by:
      sort in interface GridView
    • onChange

      public void onChange(ResourceKey resource, long amount, @Nullable TrackedResource trackedResource)
      Description copied from interface: GridView
      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).
      Specified by:
      onChange in interface GridView
      Parameters:
      resource - the resource
      amount - the amount, can be negative or positive
      trackedResource - the tracked resource, can be null
    • getViewList

      public List<GridResource> getViewList()
      Specified by:
      getViewList in interface GridView
      Returns:
      the view list
    • copyBackingList

      public ResourceList copyBackingList()
      Specified by:
      copyBackingList in interface GridView
      Returns:
      a copy of the backing list
    • clear

      public void clear()
      Description copied from interface: GridView
      Clears the backing list, view list and tracked resources index.
      Specified by:
      clear in interface GridView