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 pattern, String delimiter, IdCodec inner, UnaryOperator<IdCodec> outer) datePrefix(Period, String, IdCodec, UnaryOperator)with the period key written inpattern: withyyMMddthe id(20261124, 1)becomes"261124-1"(the 4.xgroup.pattern).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
-
datePrefix
static GroupedCodec datePrefix(Period period, String pattern, String delimiter, IdCodec inner, UnaryOperator<IdCodec> outer) datePrefix(Period, String, IdCodec, UnaryOperator)with the period key written inpattern: withyyMMddthe id(20261124, 1)becomes"261124-1"(the 4.xgroup.pattern). Only the text changes:GroupedId.period(), and so the store keys, keep the preset's pattern, and decoding gives them back.patternis read strictly inLocale.ROOT,yas the proleptic year, soyyreads 2000 to 2099. It must tell exactly the period's date: aYEAR_MONTH_DAYpattern needs the year, month and day, and none takes a field finer than the period. A pattern of fixed length, such asyyMMdd, decodes even without a delimiter; any other needs one.- Parameters:
period- the period of the keys; a preset (Period.YEAR,Period.YEAR_MONTHorPeriod.YEAR_MONTH_DAY), whose keys the codec can readpattern- the date pattern of the key in the text, such asyyMMdddelimiter- the text between the period and the value; may be empty for a pattern of fixed lengthinner- the codec of the valueouter- decorates the text that starts with the period key- Returns:
- the codec
- Throws:
IllegalArgumentException- ifperiodis not a preset, orpatterndoes not tell exactly its date
-
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
-