Interface GroupedCodec


public interface GroupedCodec
Turns a GroupedId into text and back; grouped ids have their own codec, apart from IdCodec (04-segment.md ยง3).
  • Method Details

    • encode

      String encode(GroupedId id)
      Encodes a grouped id. An implementation is thread-safe: the generators of a runtime call it concurrently.
      Parameters:
      id - the id
      Returns:
      the text, never null
      Throws:
      IllegalArgumentException - if the codec cannot encode id, such as a value outside its range
    • decode

      GroupedId decode(String text)
      Decodes text produced by encode(GroupedId).
      Parameters:
      text - the text
      Returns:
      the id
      Throws:
      IllegalArgumentException - if the text is not an encoded grouped id
      UnsupportedOperationException - if the codec cannot decode at all, such as a date prefix without a delimiter
    • datePrefix

      static GroupedCodec datePrefix(String delimiter, IdCodec valueCodec)
      The period key, delimiter, then the value through valueCodec, such as "20261026" followed by Radix.of(10, 6, true).

      Decoding splits the text at the first delimiter, so the period key must not contain it (the preset keys are digits). Without a delimiter the text cannot be split, so decode(java.lang.String) is not supported.

      Parameters:
      delimiter - the text between the period and the value
      valueCodec - the codec of the value
      Returns:
      the codec
    • datePrefix

      static GroupedCodec datePrefix(Period period, String delimiter, IdCodec valueCodec)
      datePrefix(String, IdCodec) for the keys of period: with a preset period the key has a known length, so the text decodes even without a delimiter (such as "20261026000042"). Decoding checks that the key is one of period.
      Parameters:
      period - the period of the keys
      delimiter - the text between the period and the value; may be empty for a preset period
      valueCodec - the codec of the value
      Returns:
      the codec
    • datePrefix

      static GroupedCodec datePrefix(Period period, String delimiter, IdCodec inner, UnaryOperator<IdCodec> outer)
      The period key inside a decorated text: inner turns the value into text, the period key and delimiter are prepended to it, and outer decorates the result. With outer = codec -> codec.withPrefix("BIZ-") the id (20261026, 42) becomes "BIZ-20261026-000042": the period after a business prefix, as the 4.x group-prefix with before-prefix = true (its default). outer may only decorate the text it is given (prefixes, suffixes, date prefixes); the identity gives datePrefix(Period, String, IdCodec).
      Parameters:
      period - the period of the keys
      delimiter - the text between the period and the value; may be empty for a preset period
      inner - the codec of the value
      outer - decorates the text that starts with the period key
      Returns:
      the codec
    • valueOnly

      static GroupedCodec valueOnly(IdCodec valueCodec)
      The value alone, without its period: the 4.x group-prefix with enabled = false. The text does not tell the period, so decode(java.lang.String) is not supported.
      Parameters:
      valueCodec - the codec of the value
      Returns:
      the codec