Class LocalizedDurationFormatter
java.lang.Object
com.winterhavenmc.library.messagebuilder.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, QueryHandlerFactory queryHandlerFactory) Constructs aLocalizedDurationFormatter
with a backing delegate and query handler factory. -
Method Summary
Modifier and TypeMethodDescriptionformat
(Duration duration, ChronoUnit lowerBound) Formats aDuration
into a localized string, applying special handling for unlimited or too-small durations.
-
Constructor Details
-
LocalizedDurationFormatter
public LocalizedDurationFormatter(DurationFormatter delegate, QueryHandlerFactory queryHandlerFactory) Constructs aLocalizedDurationFormatter
with a backing delegate and query handler factory.- Parameters:
delegate
- the base formatter to handle standard durationsqueryHandlerFactory
- factory for retrieving language constants from the configuration
-
-
Method Details
-
format
Formats aDuration
into a localized string, applying special handling for unlimited or too-small durations.- Specified by:
format
in 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
-