java.lang.Object
com.winterhavenmc.library.messagebuilder.pipeline.formatters.duration.LocalizedDurationFormatter
All Implemented Interfaces:
DurationFormatter

public final class LocalizedDurationFormatter extends Object implements 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) durations
  • TIME.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 Details

    • LocalizedDurationFormatter

      public LocalizedDurationFormatter(DurationFormatter delegate, QueryHandlerFactory queryHandlerFactory)
      Constructs a LocalizedDurationFormatter with a backing delegate and query handler factory.
      Parameters:
      delegate - the base formatter to handle standard durations
      queryHandlerFactory - factory for retrieving language constants from the configuration
  • Method Details

    • format

      public String format(Duration duration, ChronoUnit lowerBound)
      Formats a Duration into a localized string, applying special handling for unlimited or too-small durations.
      Specified by:
      format in interface DurationFormatter
      Parameters:
      duration - the duration to format
      lowerBound - the smallest time unit to represent (e.g., SECONDS)
      Returns:
      a formatted string representation of the duration, localized as needed