public interface GroupedCodec
-
Method Summary
Modifier and TypeMethodDescriptionstatic GroupedCodecdatePrefix(String delimiter, IdCodec valueCodec) The period key,delimiter, then the value throughvalueCodec, such as"20261026"followed byRadix.of(10, 6, true).static GroupedCodecdatePrefix(Period period, String delimiter, IdCodec valueCodec) datePrefix(String, IdCodec)for the keys ofperiod: with a preset period the key has a known length, so the text decodes even without a delimiter (such as"20261026000042").static GroupedCodecdatePrefix(Period period, String delimiter, IdCodec inner, UnaryOperator<IdCodec> outer) The period key inside a decorated text:innerturns the value into text, the period key anddelimiterare prepended to it, andouterdecorates the result.Decodes text produced byencode(GroupedId).Encodes a grouped id.static GroupedCodecThe value alone, without its period: the 4.xgroup-prefixwithenabled = false.
-
Method Details
-
encode
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 encodeid, such as a value outside its range
-
decode
Decodes text produced byencode(GroupedId).- Parameters:
text- the text- Returns:
- the id
- Throws:
IllegalArgumentException- if the text is not an encoded grouped idUnsupportedOperationException- if the codec cannot decode at all, such as a date prefix without a delimiter
-
datePrefix
The period key,delimiter, then the value throughvalueCodec, such as"20261026"followed byRadix.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, sodecode(java.lang.String)is not supported.- Parameters:
delimiter- the text between the period and the valuevalueCodec- the codec of the value- Returns:
- the codec
-
datePrefix
datePrefix(String, IdCodec)for the keys ofperiod: 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 ofperiod.- Parameters:
period- the period of the keysdelimiter- the text between the period and the value; may be empty for a preset periodvalueCodec- 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:innerturns the value into text, the period key anddelimiterare prepended to it, andouterdecorates the result. Withouter = codec -> codec.withPrefix("BIZ-")the id(20261026, 42)becomes"BIZ-20261026-000042": the period after a business prefix, as the 4.xgroup-prefixwithbefore-prefix = true(its default).outermay only decorate the text it is given (prefixes, suffixes, date prefixes); the identity givesdatePrefix(Period, String, IdCodec).- Parameters:
period- the period of the keysdelimiter- the text between the period and the value; may be empty for a preset periodinner- the codec of the valueouter- decorates the text that starts with the period key- Returns:
- the codec
-
valueOnly
The value alone, without its period: the 4.xgroup-prefixwithenabled = false. The text does not tell the period, sodecode(java.lang.String)is not supported.- Parameters:
valueCodec- the codec of the value- Returns:
- the codec
-