Interface NumberSource
- All Known Implementing Classes:
DefaultNumberSource
public interface NumberSource
A source of unique numbers.
- Author:
- harald
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionlonggetCount()Returns the count of numbers in the pool.Gets the ranges of this source.
Does not consume any numbers.booleanisEmpty()Returns whether pool is empty.booleanisOnline()Returns whether pool is online.
Offline pools reject all other methods with aNumberSourceException.longPops the next unique number from the source.popNumbers(long count) Pops the next unique numbers from the source.
If the pool runs out of numbers, fewer thancountnumbers are returned.popNumbers(long begin, long end) Pops a range or ranges of unique numbers from the source.
The returned ranges are sorted by numbers (ascending).voidpushNumber(long number) Pushes a number to the number source.
If the number is already in the number source, nothing happens.voidpushNumbers(long begin, long end) Pushes a range of unique numbers to the source.
The range may overlap with existing numbers.
-
Method Details
-
getRanges
NumberSource.Range[] getRanges()Gets the ranges of this source.
Does not consume any numbers. The ranges are not sorted and may contain empty ranges.- Returns:
- the ranges, never null
-
getCount
long getCount()Returns the count of numbers in the pool.- Returns:
- the number of numbers
-
isEmpty
boolean isEmpty()Returns whether pool is empty.- Returns:
- true if empty
-
isOnline
boolean isOnline()Returns whether pool is online.
Offline pools reject all other methods with aNumberSourceException.- Returns:
- true if online (enabled), else offline (disabled)
-
popNumber
long popNumber()Pops the next unique number from the source.- Returns:
- the next number
- Throws:
NumberSourceEmptyException- if pool is empty
-
popNumbers
Pops the next unique numbers from the source.
If the pool runs out of numbers, fewer thancountnumbers are returned.- Parameters:
count- the number count- Returns:
- the next numbers as ranges sorted by numbers (ascending), never null
- Throws:
NumberSourceEmptyException- if pool is empty
-
popNumbers
Pops a range or ranges of unique numbers from the source.
The returned ranges are sorted by numbers (ascending).- Parameters:
begin- the first numberend- the last number + 1- Returns:
- the numbers range(s) ≥
beginand <end, never null
-
pushNumber
void pushNumber(long number) Pushes a number to the number source.
If the number is already in the number source, nothing happens.- Parameters:
number- number to be pushed
-
pushNumbers
void pushNumbers(long begin, long end) Pushes a range of unique numbers to the source.
The range may overlap with existing numbers.- Parameters:
begin- the first numberend- the last number + 1
-