Interface IdCodec

All Known Implementing Classes:
Friendly, Radix

public interface IdCodec
Turns a long id into text and back (03-core-model.md ยง1).

Codecs compose: the codec list of a generator applies in the order it is written, the first item turning the id into text and the rest decorating that text, such as withPrefix(String).

  • Method Details

    • encode

      String encode(long id)
      Encodes an id (R1-core-16).
      Parameters:
      id - the id
      Returns:
      the text, never null
      Throws:
      IllegalArgumentException - if the codec cannot encode id: one outside its range, such as a negative id, or one wider than the digits of a fixed-width radix; a codec never truncates
    • decode

      long decode(String text)
      Decodes text produced by encode(long).
      Parameters:
      text - the text
      Returns:
      the id
      Throws:
      IllegalArgumentException - if the text is not an encoded id
    • withPrefix

      default IdCodec withPrefix(String prefix)
      Prepends prefix to the encoded text.
      Parameters:
      prefix - the prefix
      Returns:
      the decorated codec
    • withSuffix

      default IdCodec withSuffix(String suffix)
      Appends suffix to the encoded text.
      Parameters:
      suffix - the suffix
      Returns:
      the decorated codec