Class ResourceCounter


  • public final class ResourceCounter
    extends Object
    Counter for ResourceProfiles. This class is immutable.

    ResourceCounter contains a set of ResourceProfiles and their associated counts. The counts are always positive (> 0).

    • Method Detail

      • getResourceCount

        public int getResourceCount​(ResourceProfile resourceProfile)
        Number of resources with the given ResourceProfile.
        Parameters:
        resourceProfile - resourceProfile for which to look up the count
        Returns:
        number of resources with the given resourceProfile or 0 if the resource profile does not exist
      • getTotalResourceCount

        public int getTotalResourceCount()
        Computes the total number of resources in this counter.
        Returns:
        the total number of resources in this counter
      • getTotalResource

        public ResourceProfile getTotalResource()
        Computes the total resources in this counter.
        Returns:
        the total resources in this counter
      • add

        public ResourceCounter add​(ResourceCounter increment)
        Adds increment to this resource counter value and returns the resulting value.
        Parameters:
        increment - increment to add to this resource counter value
        Returns:
        new ResourceCounter containing the result of the addition
      • add

        public ResourceCounter add​(Map<ResourceProfile,​Integer> increment)
        Adds the given increment to this resource counter value and returns the resulting value.
        Parameters:
        increment - increment ot add to this resource counter value
        Returns:
        new ResourceCounter containing the result of the addition
      • add

        public ResourceCounter add​(ResourceProfile resourceProfile,
                                   int increment)
        Adds increment to the count of resourceProfile and returns the new value.
        Parameters:
        resourceProfile - resourceProfile to which to add increment
        increment - increment is the number by which to increase the resourceProfile
        Returns:
        new ResourceCounter containing the result of the addition
      • subtract

        public ResourceCounter subtract​(ResourceCounter decrement)
        Subtracts decrement from this resource counter value and returns the new value.
        Parameters:
        decrement - decrement to subtract from this resource counter
        Returns:
        new ResourceCounter containing the new value
      • subtract

        public ResourceCounter subtract​(Map<ResourceProfile,​Integer> decrement)
        Subtracts decrement from this resource counter value and returns the new value.
        Parameters:
        decrement - decrement to subtract from this resource counter
        Returns:
        new ResourceCounter containing the new value
      • subtract

        public ResourceCounter subtract​(ResourceProfile resourceProfile,
                                        int decrement)
        Subtracts decrement from the count of the given resourceProfile and returns the new value.
        Parameters:
        resourceProfile - resourceProfile from which to subtract decrement
        decrement - decrement is the number by which to decrease resourceProfile
        Returns:
        new ResourceCounter containing the new value
      • containsResource

        public boolean containsResource​(ResourceProfile resourceProfile)
        Checks whether resourceProfile is contained in this counter.
        Parameters:
        resourceProfile - resourceProfile to check whether it is contained
        Returns:
        true if the counter has a positive count for the given resourceProfile; otherwise false
      • isEmpty

        public boolean isEmpty()
        Checks whether the resource counter is empty.
        Returns:
        true if the counter does not contain any counts; otherwise false
      • empty

        public static ResourceCounter empty()
        Creates an empty resource counter.
        Returns:
        empty resource counter
      • withResources

        public static ResourceCounter withResources​(Map<ResourceProfile,​Integer> resources)
        Creates a resource counter with the specified set of resources.
        Parameters:
        resources - resources with which to initialize the resource counter
        Returns:
        ResourceCounter which contains the specified set of resources
      • withResource

        public static ResourceCounter withResource​(ResourceProfile resourceProfile,
                                                   int count)
        Creates a resource counter with the given resourceProfile and its count.
        Parameters:
        resourceProfile - resourceProfile for the given count
        count - count of the given resourceProfile
        Returns:
        ResourceCounter which contains the specified resourceProfile and its count
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object