Package me.ahoo.cosid

Class IntegerIdGenerator

java.lang.Object
me.ahoo.cosid.IntegerIdGenerator
All Implemented Interfaces:
StringIdGenerator

@ThreadSafe public class IntegerIdGenerator extends Object implements StringIdGenerator
Integer ID generator that adapts a long-based ID generator to produce integer IDs.

This class wraps an existing IdGenerator that produces long IDs and provides methods to generate integer IDs instead. This is useful when working with systems or databases that require integer primary keys rather than longs.

Note that integer IDs have a much smaller range than long IDs (approximately +/- 2.1 billion vs +/- 9.2 quintillion), so this generator throws an IntegerIdGenerator.IdOverflowException when the underlying long ID exceeds the integer range.

This class implements StringIdGenerator to provide string ID generation capabilities as well, using the wrapped generator's ID converter.

Implementations of this class are thread-safe and can be used concurrently across multiple threads.

  • Field Details

    • actual

      protected final IdGenerator actual
      The actual ID generator that produces long IDs.

      This generator is used as the source of IDs, which are then converted to integer format when requested.

  • Constructor Details

    • IntegerIdGenerator

      public IntegerIdGenerator(IdGenerator actual)
      Create a new IntegerIdGenerator that wraps the specified long ID generator.

      The provided generator will be used to produce the underlying long IDs that are then converted to integers when requested.

      Parameters:
      actual - The actual ID generator that produces long IDs
  • Method Details