public final class ResourceCounter extends Object
ResourceProfiles. This class is immutable.
ResourceCounter contains a set of ResourceProfiles and their
associated counts. The counts are always positive (> 0).
| Modifier and Type | Method and Description |
|---|---|
ResourceCounter |
add(Map<ResourceProfile,Integer> increment)
Adds the given increment to this resource counter value and returns the resulting value.
|
ResourceCounter |
add(ResourceCounter increment)
Adds increment to this resource counter value and returns the resulting value.
|
ResourceCounter |
add(ResourceProfile resourceProfile,
int increment)
Adds increment to the count of resourceProfile and returns the new value.
|
boolean |
containsResource(ResourceProfile resourceProfile)
Checks whether resourceProfile is contained in this counter.
|
static ResourceCounter |
empty()
Creates an empty resource counter.
|
boolean |
equals(Object o) |
int |
getResourceCount(ResourceProfile resourceProfile)
Number of resources with the given
ResourceProfile. |
Set<ResourceProfile> |
getResources()
Gets all stored
ResourceProfiles. |
Collection<Map.Entry<ResourceProfile,Integer>> |
getResourcesWithCount()
Gets the stored resources and their counts.
|
ResourceProfile |
getTotalResource()
Computes the total resources in this counter.
|
int |
getTotalResourceCount()
Computes the total number of resources in this counter.
|
int |
hashCode() |
boolean |
isEmpty()
Checks whether the resource counter is empty.
|
ResourceCounter |
subtract(Map<ResourceProfile,Integer> decrement)
Subtracts decrement from this resource counter value and returns the new value.
|
ResourceCounter |
subtract(ResourceCounter decrement)
Subtracts decrement from this resource counter value and returns the new value.
|
ResourceCounter |
subtract(ResourceProfile resourceProfile,
int decrement)
Subtracts decrement from the count of the given resourceProfile and returns the new value.
|
String |
toString() |
static ResourceCounter |
withResource(ResourceProfile resourceProfile,
int count)
Creates a resource counter with the given resourceProfile and its count.
|
static ResourceCounter |
withResources(Map<ResourceProfile,Integer> resources)
Creates a resource counter with the specified set of resources.
|
public int getResourceCount(ResourceProfile resourceProfile)
ResourceProfile.resourceProfile - resourceProfile for which to look up the count0 if the resource
profile does not existpublic int getTotalResourceCount()
public ResourceProfile getTotalResource()
public ResourceCounter add(ResourceCounter increment)
increment - increment to add to this resource counter valuepublic ResourceCounter add(Map<ResourceProfile,Integer> increment)
increment - increment ot add to this resource counter valuepublic ResourceCounter add(ResourceProfile resourceProfile, int increment)
resourceProfile - resourceProfile to which to add incrementincrement - increment is the number by which to increase the resourceProfilepublic ResourceCounter subtract(ResourceCounter decrement)
decrement - decrement to subtract from this resource counterpublic ResourceCounter subtract(Map<ResourceProfile,Integer> decrement)
decrement - decrement to subtract from this resource counterpublic ResourceCounter subtract(ResourceProfile resourceProfile, int decrement)
resourceProfile - resourceProfile from which to subtract decrementdecrement - decrement is the number by which to decrease resourceProfilepublic Collection<Map.Entry<ResourceProfile,Integer>> getResourcesWithCount()
ResourceProfile and count pairspublic boolean containsResource(ResourceProfile resourceProfile)
resourceProfile - resourceProfile to check whether it is containedtrue if the counter has a positive count for the given resourceProfile;
otherwise falsepublic Set<ResourceProfile> getResources()
ResourceProfiles.ResourceProfilespublic boolean isEmpty()
true if the counter does not contain any counts; otherwise falsepublic static ResourceCounter empty()
public static ResourceCounter withResources(Map<ResourceProfile,Integer> resources)
resources - resources with which to initialize the resource counterpublic static ResourceCounter withResource(ResourceProfile resourceProfile, int count)
resourceProfile - resourceProfile for the given countcount - count of the given resourceProfileCopyright © 2014–2025 The Apache Software Foundation. All rights reserved.