Class Codecs

java.lang.Object
me.ahoo.cosid.internal.Codecs

public final class Codecs extends Object
Builds the codecs of a runtime from their specs (07-runtime-and-spring.md ยง4.1): a codec list applies in order, its first item turns the id into text and the rest decorate the text.
  • Field Details

    • DECIMAL

      public static final IdCodec DECIMAL
      The codec of an empty list: the decimal digits, as Long.toString.
  • Constructor Details

    • Codecs

      public Codecs(TimeSource time, Function<String,Optional<IdCodec>> custom)
      Codecs built against one time source and custom codec resolver.
      Parameters:
      time - the time source of NOW date prefixes
      custom - resolves custom codec references
  • Method Details

    • ids

      public IdCodec ids(List<CodecSpec> specs, Optional<Layout> layout)
      The codec of a long generator.
      Parameters:
      specs - the codec list
      layout - the generator's layout; empty for segments
      Returns:
      the codec
      Throws:
      IllegalArgumentException - if the list is invalid for the generator
    • decorate

      public IdCodec decorate(IdCodec codec, List<CodecSpec> specs, Optional<Layout> layout)
      Decorates the text of a codec with a list of decorations (prefixes, suffixes, date prefixes).
      Parameters:
      codec - the codec whose text the list decorates
      specs - the decorations, applied in order
      layout - the generator's layout; empty for segments
      Returns:
      the decorated codec
      Throws:
      IllegalArgumentException - if an item turns the id into text instead of decorating it
    • parts

      public static PartsCodec parts(PartsCodecSpec spec, Layout layout)
      The codec of a cosid80 generator.
      Parameters:
      spec - the spec
      layout - the generator's layout
      Returns:
      the parts codec
    • grouped

      public GroupedCodec grouped(GroupedCodecSpec spec, Period period)
      The codec of a periodic segment generator.
      Parameters:
      spec - the spec
      period - the generator's period, which gives the length of the key
      Returns:
      the grouped codec