Class StaticDurationFormat

java.lang.Object
io.github.blackbaroness.durationserializer.format.impl.StaticDurationFormat
All Implemented Interfaces:
DurationFormat
Direct Known Subclasses:
FullWordEnglishDurationFormat, MediumLenghtRussianDurationFormat, MediumLengthEnglishDurationFormat, ShortEnglishDurationFormat, ShortRussianDurationFormat

public abstract class StaticDurationFormat extends Object implements DurationFormat
  • Constructor Details

    • StaticDurationFormat

      public StaticDurationFormat(String nanosecondsFormat, String millisecondsFormat, String secondsFormat, String minutesFormat, String hoursFormat, String daysFormat)
  • Method Details

    • serialize

      @NotNull public @NotNull String serialize(@NotNull @NotNull DurationUnit unit, @org.jetbrains.annotations.Range(from=0L, to=9223372036854775807L) long amount)
      Description copied from interface: DurationFormat
      Formats the given duration into a string.

      For example, it can convert MINUTES and 5 to "5 minutes".

      Specified by:
      serialize in interface DurationFormat
      Parameters:
      unit - duration unit
      amount - duration amount
      Returns:
      string representation of duration unit with specified amount
    • deserialize

      @NotNull public @NotNull Duration deserialize(@NotNull @NotNull String unitInput, @org.jetbrains.annotations.Range(from=0L, to=9223372036854775807L) long amountInput) throws InvalidFormatException
      Description copied from interface: DurationFormat
      Parses the given string into a duration unit.

      For example, it can convert "5 minutes" to Duration.ofMinutes(5).

      Specified by:
      deserialize in interface DurationFormat
      Parameters:
      unitInput - input string which should contain only duration unit string representation
      amountInput - time amount
      Returns:
      parsed duration
      Throws:
      InvalidFormatException - if input string is not a valid duration unit