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.
  • Method Details

    • add

      ResourceList.OperationResult add(ResourceKey resource, long amount)
      Adds a given resource to the list.
      Parameters:
      resource - the resource, may not be null
      amount - the amount, must be larger than 0
      Returns:
      the result of the operation
    • add

      default ResourceList.OperationResult add(ResourceAmount resourceAmount)
      Adds a given resource to the list. Shorthand for add(ResourceKey, long).
      Parameters:
      resourceAmount - the resource and the amount
      Returns:
      the result of the operation
    • remove

      Optional<ResourceList.OperationResult> remove(ResourceKey resource, long amount)
      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 null
      amount - the amount, must be larger than 0
      Returns:
      a result if the removal operation was successful, otherwise an empty Optional
    • remove

      default Optional<ResourceList.OperationResult> remove(ResourceAmount resourceAmount)
      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 for remove(ResourceKey, long).
      Parameters:
      resourceAmount - the resource and the amount
      Returns:
      a result if the removal operation was successful, otherwise an empty Optional
    • 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

      long get(ResourceKey resource)
      Parameters:
      resource - the resource
      Returns:
      the amount stored, or zero if not stored
    • contains

      boolean contains(ResourceKey resource)
      Parameters:
      resource - the resource
      Returns:
      whether the list contains this resource
    • clear

      void clear()
      Clears the list.
    • copy

      ResourceList copy()
      Copies the list.