Package com.atlassian.crowd.util
Class BoundedCount
java.lang.Object
com.atlassian.crowd.util.BoundedCount
A possibly approximate count of the number of elements in a collection. The collection has at least
getCount()
elements. A count marked as exact has exactly count elements (see isExact()
. This allows APIs to give
indications of collection size without committing to expensive operations when an exact count requires
significant work.
Provided are some example scenarios and what the results mean:
- (getCount(), isExact())
- result
- (5, true)
- Count of elements is exactly 5
- (5, false)
- Count of elements is at least 5
- (0, false)
- Count of elements is zero or more (could be anything)
-
Method Summary
Modifier and TypeMethodDescriptionstatic BoundedCount
atLeast
(long count) Create a BoundedCount that is at-least as big as a given number.boolean
static BoundedCount
exactly
(long count) Create a bounded count that exactly represents a number.static BoundedCount
fromCountedItemsAndLimit
(long count, long potentialMaxCount) Get a bounded count from counting up to an upper bound.long
getCount()
The number of elements counted in a collection.int
hashCode()
boolean
isExact()
toString()
-
Method Details
-
exactly
Create a bounded count that exactly represents a number.- Parameters:
count
- The exact count that this represents; not a bounded number.- Returns:
- A BoundedCount that is exact.
-
atLeast
Create a BoundedCount that is at-least as big as a given number. This creates a lower bound on the provided count allowing you to indicate that the collection you are counting is bigger than a given count.- Parameters:
count
- A number that is at-least as big as the real count of elements in a collection.- Returns:
- A lower bounded count.
-
fromCountedItemsAndLimit
Get a bounded count from counting up to an upper bound.- Parameters:
count
- The number of elements that were actually counted.potentialMaxCount
- The maximum number of elements that we counted up to.- Returns:
- Returns exactly the count given (if less than the upper bound) and returns at-least the upper bound otherwise.
-
getCount
public long getCount()The number of elements counted in a collection.- Returns:
- If
isExact()
returns true then it returns the exact size of the collection. Otherwise it returns a lower bound of the size of the collection. The answer will always be non-negative.
-
isExact
public boolean isExact()- Returns:
- True if
getCount()
is known to be the exact number of elements in the collection. It will return False if this count represents a lower bound.
-
equals
-
hashCode
public int hashCode() -
toString
-