Class StringSegmentId

java.lang.Object
me.ahoo.cosid.StringIdGeneratorDecorator
me.ahoo.cosid.segment.StringSegmentId
All Implemented Interfaces:
AutoCloseable, Decorator<IdGenerator>, IdGenerator, IdGeneratorDecorator, SegmentId, Statistical, StringIdGenerator

public class StringSegmentId extends StringIdGeneratorDecorator implements SegmentId, AutoCloseable
String-based SegmentId wrapper.

Wraps a SegmentId with a string converter for generating string-based IDs while maintaining segment functionality.

  • Constructor Details

    • StringSegmentId

      public StringSegmentId(SegmentId actual, IdConverter idConverter)
      Creates a new StringSegmentId.
      Parameters:
      actual - the underlying segment ID
      idConverter - the converter for string generation
  • Method Details

    • close

      public void close() throws Exception
      Close the decorated segment id when it is AutoCloseable, such as a SegmentChainId.
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception - if closing it fails
    • generateAsString

      public @NonNull String generateAsString()
      Converts with the group of the id when the converter uses it, so a grouped prefix comes from the segment the id came from.
      Specified by:
      generateAsString in interface IdGenerator
      Specified by:
      generateAsString in interface StringIdGenerator
      Returns:
      A unique distributed ID as a string value
    • current

      public IdSegment current()
      Description copied from interface: SegmentId
      Get the current ID segment being used for generation.

      This method returns the segment from which IDs are currently being allocated. The segment contains the range of available IDs and tracks the current position within that range.

      Specified by:
      current in interface SegmentId
      Returns:
      The current ID segment
    • generateGrouped

      public @NonNull GroupedId generateGrouped()
      Description copied from interface: SegmentId
      Generate an id together with the group of the segment it came from.
      Specified by:
      generateGrouped in interface SegmentId
      Returns:
      the id and its group, GroupedKey.NEVER when it is not grouped
    • stat

      public IdGeneratorStat stat()
      Description copied from interface: SegmentId
      Get statistical information about this Segment ID generator.

      This method provides detailed information about the generator's current state, including segment metadata and availability status.

      Specified by:
      stat in interface IdGenerator
      Specified by:
      stat in interface IdGeneratorDecorator
      Specified by:
      stat in interface SegmentId
      Specified by:
      stat in interface Statistical
      Specified by:
      stat in interface StringIdGenerator
      Returns:
      Statistical information about this Segment ID generator