Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface Durationable
Represents an object that exposes a Duration, enabling it to participate in macro substitution using duration-based placeholders.

Objects implementing this interface can provide a duration value via getDuration(), and automatically extract localized string representations of that duration through the extractDuration(MacroKey, ChronoUnit, AdapterContextContainer) method.

This interface supports usage in message templates via the [OBJECT.DURATION} macro. Formatting is handled by the DurationFormatter implementation provided in the AdapterContextContainer.

Three utility methods are provided:

Durations are automatically classified using the DurationType enum into:

  • NORMAL — durations above 1 unit
  • LESS_THAN — durations under the specified ChronoUnit lower bound
  • UNLIMITED — negative durations signifying no expiration or restriction
See Also:
  • Method Details

    • getDuration

      Duration getDuration()
      Returns the duration value associated with this object.
      Returns:
      the duration, or null if unavailable
    • extractDuration

      default MacroStringMap extractDuration(MacroKey baseKey, ChronoUnit lowerBound, AdapterContextContainer ctx)
      Extracts a MacroStringMap containing a single entry mapping the provided MacroKey (with .DURATION appended) to a localized string representation of this object's duration.
      Parameters:
      baseKey - the top-level key to which DURATION will be appended
      lowerBound - the smallest ChronoUnit to display (e.g., MINUTES, SECONDS)
      ctx - context container providing the DurationFormatter
      Returns:
      a MacroStringMap containing the extracted duration string; empty if the key could not be constructed
    • formatDuration

      static Optional<String> formatDuration(Duration duration, ChronoUnit lowerBound, DurationFormatter durationFormatter)
      Uses the configured DurationFormatter to format the given Duration according to the specified precision.
      Parameters:
      duration - the duration to format
      lowerBound - the lowest precision unit to include in the result (e.g., seconds, minutes)
      durationFormatter - the formatter to use for localization
      Returns:
      an Optional<String> containing the formatted result, or empty if input is null
    • durationUntil

      static Duration durationUntil(Instant instant)
      Computes the duration from the current moment until the given Instant.
      Parameters:
      instant - a future point in time
      Returns:
      the computed duration, or Duration.ZERO if the instant is null