Enum Class DurationFormat.Unit

java.lang.Object
java.lang.Enum<DurationFormat.Unit>
org.springframework.format.annotation.DurationFormat.Unit
All Implemented Interfaces:
Serializable, Comparable<DurationFormat.Unit>, Constable
Enclosing class:
DurationFormat

public static enum DurationFormat.Unit extends Enum<DurationFormat.Unit>
Duration format unit, which mirrors a subset of ChronoUnit and allows conversion to and from supported ChronoUnit as well as converting durations to longs. The enum includes its corresponding suffix in the simple Duration format style.
  • Enum Constant Details

  • Method Details

    • values

      public static DurationFormat.Unit[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static DurationFormat.Unit valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • asChronoUnit

      public ChronoUnit asChronoUnit()
      Convert this DurationFormat.Unit to its ChronoUnit equivalent.
    • asSuffix

      public String asSuffix()
      Convert this DurationFormat.Unit to a simple String suffix, suitable for the DurationFormat.Style.SIMPLE style.
    • parse

      public Duration parse(String value)
      Parse a long from a String and interpret it to be a Duration in the current unit.
      Parameters:
      value - the String representation of the long
      Returns:
      the corresponding Duration
    • print

      public String print(Duration value)
      Print a Duration as a String, converting it to a long value using this unit's precision via longValue(Duration) and appending this unit's simple suffix.
      Parameters:
      value - the Duration to convert to String
      Returns:
      the String representation of the Duration in the SIMPLE style
    • longValue

      public long longValue(Duration value)
      Convert the given Duration to a long value in the resolution of this unit. Note that this can be lossy if the current unit is bigger than the actual resolution of the duration.

      For example, Duration.ofMillis(5).plusNanos(1234) would get truncated to 5 for unit MILLIS.

      Parameters:
      value - the Duration to convert to long
      Returns:
      the long value for the Duration in this Unit
    • fromChronoUnit

      public static DurationFormat.Unit fromChronoUnit(@Nullable ChronoUnit chronoUnit)
      Get the Unit corresponding to the given ChronoUnit.
      Throws:
      IllegalArgumentException - if that particular ChronoUnit isn't supported
    • fromSuffix

      public static DurationFormat.Unit fromSuffix(String suffix)
      Get the Unit corresponding to the given String suffix.
      Throws:
      IllegalArgumentException - if that particular suffix is unknown