Package me.ahoo.cosid

Interface IdConverter

All Superinterfaces:
Statistical
All Known Implementing Classes:
DatePrefixIdConverter, GroupedPrefixIdConverter, PrefixIdConverter, Radix36IdConverter, Radix62IdConverter, RadixIdConverter, SnowflakeFriendlyIdConverter, SuffixIdConverter, ToStringIdConverter

@ThreadSafe public interface IdConverter extends Statistical
ID converter for transforming between numeric and string representations of IDs.

This interface defines the contract for converting distributed IDs between their numeric (long) and string representations. This is useful when you need to store IDs as strings in databases or URLs but work with them as numbers in application logic.

Common implementations include:

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

  • Method Summary

    Modifier and Type
    Method
    Description
    long
    asLong(String idString)
    Convert a String type ID back to its long representation.
    asString(long id)
    Convert a long type ID to its String representation.
    default Stat
    Get statistical information about this converter.
  • Method Details

    • asString

      @Nonnull String asString(long id)
      Convert a long type ID to its String representation.

      This method transforms a numeric ID into a string format according to the specific conversion algorithm implemented by the converter. For example, a radix converter might convert the number 12345 to "3d7".

      Parameters:
      id - The long type ID to convert
      Returns:
      The String representation of the ID
    • asLong

      long asLong(@Nonnull String idString)
      Convert a String type ID back to its long representation.

      This method performs the reverse operation of asString(long), transforming a string ID back into its original numeric form. Implementations should be able to correctly parse strings generated by their asString(long) method.

      Parameters:
      idString - The String type ID to convert
      Returns:
      The long representation of the ID
    • stat

      default Stat stat()
      Get statistical information about this converter.

      This method provides basic statistical information about the converter, including its implementation class name.

      Specified by:
      stat in interface Statistical
      Returns:
      Statistical information about this converter