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 Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the backing list and view list.long
getAmount
(ResourceKey resource) boolean
isSticky
(ResourceKey resource) setFilterAndSort
(ResourceRepositoryFilter<T> filter) void
setListener
(Runnable listener) Sets a listener that is called when the view list changes.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.void
setSort
(Comparator<T> sort, SortingDirection direction) After changing the sort, you still need to callsort()
.void
sort()
Sorts the view list.void
update
(ResourceKey resource, long amount) Applies a change to a resource.
-
Method Details
-
setListener
Sets a listener that is called when the view list changes.- Parameters:
listener
- the listener, can be null
-
setSort
After changing the sort, you still need to callsort()
.- Parameters:
sort
- the sortdirection
- 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 callsort()
.- 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
- Parameters:
resource
- the resource- Returns:
- the amount in the view, or zero if not present
-
isSticky
- Parameters:
resource
- the resource- Returns:
- whether the resource is sticky
-
sort
void sort()Sorts the view list. Applies sorting and filtering rules. -
update
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 resourceamount
- the amount, can be negative or positive, but not zero
-
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.
-