Interface ResourceList
- All Known Subinterfaces:
FuzzyResourceList
- All Known Implementing Classes:
AbstractProxyResourceList
,FuzzyResourceListImpl
,ListenableResourceList
,ResourceListImpl
@API(status=STABLE,
since="2.0.0-milestone.1.2")
public interface ResourceList
Represents a list of a resource of an arbitrary type.
A basic implementation of this class can be found in
ResourceListImpl
.-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic final record
Represents the result of an operation in aResourceList
. -
Method Summary
Modifier and TypeMethodDescriptiondefault ResourceList.OperationResult
add
(ResourceAmount resourceAmount) Adds a given resource to the list.add
(ResourceKey resource, long amount) Adds a given resource to the list.void
clear()
Clears the list.boolean
contains
(ResourceKey resource) copy()
Copies the list.Retrieves all resources and their amounts from the list.long
get
(ResourceKey resource) getAll()
default Optional
<ResourceList.OperationResult> remove
(ResourceAmount resourceAmount) Removes an amount of a certain resource in the list.remove
(ResourceKey resource, long amount) Removes an amount of a certain resource in the list.
-
Method Details
-
add
Adds a given resource to the list.- Parameters:
resource
- the resource, may not be nullamount
- the amount, must be larger than 0- Returns:
- the result of the operation
-
add
Adds a given resource to the list. Shorthand foradd(ResourceKey, long)
.- Parameters:
resourceAmount
- the resource and the amount- Returns:
- the result of the operation
-
remove
Removes an amount of a certain resource in the list. If the amount reaches 0 due to this removal, the resource is removed from the list.- Parameters:
resource
- the resource, may not be nullamount
- the amount, must be larger than 0- Returns:
- a result if the removal operation was successful, otherwise an empty
Optional
-
remove
Removes an amount of a certain resource in the list. If the amount reaches 0 due to this removal, the resource is removed from the list. Shorthand forremove(ResourceKey, long)
.- Parameters:
resourceAmount
- the resource and the amount- Returns:
- a result if the removal operation was successful, otherwise an empty
Optional
-
copyState
Collection<ResourceAmount> copyState()Retrieves all resources and their amounts from the list.- Returns:
- a list of resource amounts
-
getAll
Set<ResourceKey> getAll()- Returns:
- set of resources contained in this list
-
get
- Parameters:
resource
- the resource- Returns:
- the amount stored, or zero if not stored
-
contains
- Parameters:
resource
- the resource- Returns:
- whether the list contains this resource
-
clear
void clear()Clears the list. -
copy
ResourceList copy()Copies the list.
-