Class ResourceRepositoryImpl<T>
java.lang.Object
com.refinedmods.refinedstorage.api.resource.repository.ResourceRepositoryImpl<T>
- All Implemented Interfaces:
ResourceRepository<T>
@API(status=STABLE,
since="2.0.0-milestone.1.0")
public class ResourceRepositoryImpl<T>
extends Object
implements ResourceRepository<T>
-
Constructor Summary
ConstructorsConstructorDescriptionResourceRepositoryImpl
(ResourceRepositoryMapper<T> mapper, MutableResourceList backingList, Set<ResourceKey> stickyResources, Function<ResourceRepository<T>, Comparator<T>> identitySortingType, Function<ResourceRepository<T>, Comparator<T>> defaultSortingType) -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the backing list and view list.long
getAmount
(ResourceKey resource) boolean
isSticky
(ResourceKey resource) setFilterAndSort
(ResourceRepositoryFilter<T> theFilter) void
setListener
(Runnable listener) Sets a listener that is called when the view list changes.boolean
setPreventSorting
(boolean thePreventSorting) 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.void
setSort
(Comparator<T> theSort, SortingDirection direction) After changing the sort, you still need to callResourceRepository.sort()
.void
sort()
Sorts the view list.void
update
(ResourceKey resource, long amount) Applies a change to a resource.
-
Constructor Details
-
ResourceRepositoryImpl
public ResourceRepositoryImpl(ResourceRepositoryMapper<T> mapper, MutableResourceList backingList, Set<ResourceKey> stickyResources, Function<ResourceRepository<T>, Comparator<T>> identitySortingType, Function<ResourceRepository<T>, Comparator<T>> defaultSortingType) - Parameters:
mapper
- a mapper that transforms resources to the representation in the view listbackingList
- the backing liststickyResources
- resources which must stay in the view listidentitySortingType
- a sorting type required to keep a consistent sorting order with quantity sortingdefaultSortingType
- the default sorting type
-
-
Method Details
-
setListener
Description copied from interface:ResourceRepository
Sets a listener that is called when the view list changes.- Specified by:
setListener
in interfaceResourceRepository<T>
- Parameters:
listener
- the listener, can be null
-
setSort
Description copied from interface:ResourceRepository
After changing the sort, you still need to callResourceRepository.sort()
.- Specified by:
setSort
in interfaceResourceRepository<T>
- Parameters:
theSort
- the sortdirection
- the direction
-
setFilterAndSort
- Specified by:
setFilterAndSort
in interfaceResourceRepository<T>
- Parameters:
theFilter
- the filter- Returns:
- the previous filter
-
setPreventSorting
public boolean setPreventSorting(boolean thePreventSorting) Description copied from interface:ResourceRepository
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 callResourceRepository.sort()
.- Specified by:
setPreventSorting
in interfaceResourceRepository<T>
- Parameters:
thePreventSorting
- whether the view should prevent sorting on changes- Returns:
- whether prevent sorting has changed
-
getAmount
- Specified by:
getAmount
in interfaceResourceRepository<T>
- Parameters:
resource
- the resource- Returns:
- the amount in the view, or zero if not present
-
isSticky
- Specified by:
isSticky
in interfaceResourceRepository<T>
- Parameters:
resource
- the resource- Returns:
- whether the resource is sticky
-
sort
public void sort()Description copied from interface:ResourceRepository
Sorts the view list. Applies sorting and filtering rules.- Specified by:
sort
in interfaceResourceRepository<T>
-
update
Description copied from interface:ResourceRepository
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:
update
in interfaceResourceRepository<T>
- Parameters:
resource
- the resourceamount
- the amount, can be negative or positive, but not zero
-
getViewList
- Specified by:
getViewList
in interfaceResourceRepository<T>
- Returns:
- the view list
-
copyBackingList
- Specified by:
copyBackingList
in interfaceResourceRepository<T>
- Returns:
- a copy of the backing list
-
clear
public void clear()Description copied from interface:ResourceRepository
Clears the backing list and view list.- Specified by:
clear
in interfaceResourceRepository<T>
-