Class DatePrefixIdConverter
- All Implemented Interfaces:
Decorator<IdConverter>,IdConverter,Statistical
This converter wraps another IdConverter and adds a date-based prefix, useful for time-based partitioning or bucketing of IDs.
-
Constructor Summary
ConstructorsConstructorDescriptionDatePrefixIdConverter(String pattern, String delimiter, IdConverter actual) Creates a new DatePrefixIdConverter. -
Method Summary
Modifier and TypeMethodDescriptionlongConvert aStringtype ID back to itslongrepresentation.@NonNull StringasString(long id) Convert alongtype ID to itsStringrepresentation.@NonNull StringasString(long id, @NonNull GroupedKey group) Convert an id from a segment ofgroupto itsStringrepresentation.@NonNull IdConverterGet the actual (wrapped) object that this decorator is enhancing.stat()Get statistical information about this converter.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.ahoo.cosid.IdConverter
asString
-
Constructor Details
-
DatePrefixIdConverter
Creates a new DatePrefixIdConverter.- Parameters:
pattern- date format pattern (seeDateTimeFormatter)delimiter- delimiter between prefix and IDactual- the underlying converter to wrap
-
-
Method Details
-
asString
Description copied from interface:IdConverterConvert alongtype ID to itsStringrepresentation.This method transforms a numeric ID into a string format according to the specific conversion algorithm implemented by the converter. For example, a radix converter might convert the number 12345 to "3d7".
- Specified by:
asStringin interfaceIdConverter- Parameters:
id- Thelongtype ID to convert- Returns:
- The
Stringrepresentation of the ID
-
asString
Description copied from interface:IdConverterConvert an id from a segment ofgroupto itsStringrepresentation.Converters that do not depend on the group ignore it, which is the default; decorators pass it on to the converter they wrap. A group-aware converter such as
GroupedPrefixIdConverteronly works through this method.A custom decorator that does not override this method falls back to
IdConverter.asString(long)of the converter it wraps and loses the group: override it and passgroupon.- Specified by:
asStringin interfaceIdConverter- Parameters:
id- the idgroup- the group of the segment the id came from,GroupedKey.NEVERwhen it is not grouped- Returns:
- the
Stringrepresentation of the id
-
asLong
Description copied from interface:IdConverterConvert aStringtype ID back to itslongrepresentation.This method performs the reverse operation of
IdConverter.asString(long), transforming a string ID back into its original numeric form. Implementations should be able to correctly parse strings generated by theirIdConverter.asString(long)method.- Specified by:
asLongin interfaceIdConverter- Parameters:
idString- TheStringtype ID to convert- Returns:
- The
longrepresentation of the ID
-
getActual
Description copied from interface:DecoratorGet the actual (wrapped) object that this decorator is enhancing.This method returns the underlying object that this decorator is wrapping. For ID generators, this would typically be the base generator that is being enhanced with additional functionality.
- Specified by:
getActualin interfaceDecorator<IdConverter>- Returns:
- The actual object being decorated
-
stat
Description copied from interface:IdConverterGet statistical information about this converter.This method provides basic statistical information about the converter, including its implementation class name.
- Specified by:
statin interfaceIdConverter- Specified by:
statin interfaceStatistical- Returns:
- Statistical information about this converter
-