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.
    long
    Pops 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).
    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.
      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

      NumberSource.Range[] popNumbers(long count)
      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

      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 start of range
      end - the end of range
      Returns:
      the numbers range(s) ≥ start 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 start of range
      end - the end of range