Interface PartsCodec


public interface PartsCodec
Encodes the parts of a time-based id as text; the only output of ids wider than 63 bits, such as Layout.COSID_80 (D4). Replaces the 4.x Radix62CosIdGenerator, Radix36CosIdGenerator, FriendlyCosIdGenerator and their state parsers.
  • Method Summary

    Modifier and Type
    Method
    Description
    decode(String text)
    Decodes text produced by encode(IdParts).
    encode(IdParts parts)
    Encodes the parts of an id.
    static PartsCodec
    friendly(Layout layout, ZoneId zone)
    The time part as yyyyMMddHHmmssSSS in zone, then the node and the sequence.
    static PartsCodec
    friendly(Layout layout, ZoneId zone, boolean padStart)
    The time part as yyyyMMddHHmmssSSS in zone, then the node and the sequence, padded or not.
    static PartsCodec
    radix(Layout layout, int radix)
    Each part in radix at the fixed width its bits need, so the text sorts like the id.
  • Method Details

    • encode

      String encode(IdParts parts)
      Encodes the parts of an id. An implementation is thread-safe: the generators of a runtime call it concurrently.
      Parameters:
      parts - the parts
      Returns:
      the text, never null
      Throws:
      IllegalArgumentException - if the codec cannot encode the parts, such as parts wider than its layout
    • decode

      IdParts decode(String text)
      Decodes text produced by encode(IdParts).
      Parameters:
      text - the text
      Returns:
      the parts
      Throws:
      IllegalArgumentException - if the text is not encoded parts
    • radix

      static PartsCodec radix(Layout layout, int radix)
      Each part in radix at the fixed width its bits need, so the text sorts like the id.
      Parameters:
      layout - the layout of the parts
      radix - the base, from 2 to 62
      Returns:
      the codec
    • friendly

      static PartsCodec friendly(Layout layout, ZoneId zone)
      The time part as yyyyMMddHHmmssSSS in zone, then the node and the sequence.

      As with Friendly, the repeated hour when a daylight-saving zone goes back decodes to the earlier instant; use UTC or a fixed-offset zone when parts must decode exactly.

      Parameters:
      layout - the layout of the parts
      zone - the time zone of the time part
      Returns:
      the codec
    • friendly

      static PartsCodec friendly(Layout layout, ZoneId zone, boolean padStart)
      The time part as yyyyMMddHHmmssSSS in zone, then the node and the sequence, padded or not.
      Parameters:
      layout - the layout of the parts
      zone - the time zone of the time part
      padStart - pad the node and the sequence to the width their bits need
      Returns:
      the codec