Class LocalizedDurationFormatter
java.lang.Object
com.winterhavenmc.library.messagebuilder.adapters.pipeline.formatters.duration.LocalizedDurationFormatter
- All Implemented Interfaces:
DurationFormatter
A
DurationFormatter implementation that localizes duration strings using configurable
constants from the language file, while delegating formatting of standard durations to another formatter.
This class wraps a delegate DurationFormatter, enhancing it with support for
localized representations of special duration types such as UNLIMITED and LESS_THAN.
The localized constants are fetched from the CONSTANTS section of the language file using
the following keys:
TIME.UNLIMITED– defines the display string for unlimited (negative) durationsTIME.LESS_THAN– a template string for durations shorter than the given precision
If the constants are not found or improperly configured, fallback values from the associated
DurationType enum are used.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionLocalizedDurationFormatter(DurationFormatter delegate, ConstantRepository constants) Constructs aLocalizedDurationFormatterwith a backing delegate and query handler factory. -
Method Summary
Modifier and TypeMethodDescriptionformat(Duration duration, ChronoUnit lowerBound) Formats aDurationinto a localized string, applying special handling for unlimited or too-small durations.
-
Constructor Details
-
LocalizedDurationFormatter
Constructs aLocalizedDurationFormatterwith a backing delegate and query handler factory.- Parameters:
delegate- the base formatter to handle standard durations
-
-
Method Details
-
format
Formats aDurationinto a localized string, applying special handling for unlimited or too-small durations.- Specified by:
formatin interfaceDurationFormatter- Parameters:
duration- the duration to formatlowerBound- the smallest time unit to represent (e.g., SECONDS)- Returns:
- a formatted string representation of the duration, localized as needed
-