Interface NumberSource

All Known Implementing Classes:
DefaultNumberSource

public interface NumberSource
A source of unique numbers.
Author:
harald
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static final record 
    A range of numbers.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Returns the count of numbers in the pool.
    Gets the ranges of this source.
    Does not consume any numbers.
    boolean
    Returns whether pool is empty.
    boolean
    Returns whether pool is online.
    Offline pools reject all other methods with a NumberSourceException.
    long
    Pops 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 than count numbers 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).
    void
    pushNumber(long number)
    Pushes a number to the number source.
    If the number is already in the number source, nothing happens.
    void
    pushNumbers(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 a NumberSourceException.
      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

      NumberSource.Range[] popNumbers(long count)
      Pops the next unique numbers from the source.
      If the pool runs out of numbers, fewer than count numbers 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

      NumberSource.Range[] popNumbers(long begin, long end)
      Pops a range or ranges of unique numbers from the source.
      The returned ranges are sorted by numbers (ascending).
      Parameters:
      begin - the first number
      end - the last number + 1
      Returns:
      the numbers range(s) ≥ begin and < 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 number
      end - the last number + 1