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.longPops the next unique number from the source.popNumbers(long count) Pops the next unique numbers from the source.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.- 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.- 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.- Parameters:
count- the number count- Returns:
- the next numbers as ranges, 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 start of rangeend- the end of range- Returns:
- the numbers range(s) ≥
startand <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 start of rangeend- the end of range
-