Package org.springframework.boot.convert
Enum DurationStyle
- java.lang.Object
- java.lang.Enum<DurationStyle>
- org.springframework.boot.convert.DurationStyle
- All Implemented Interfaces:
Serializable
,Comparable<DurationStyle>
public enum DurationStyle extends Enum<DurationStyle>
Duration format styles.- Since:
- 2.0.0
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static DurationStyle
detect(String value)
Detect the style from the given source value.static Duration
detectAndParse(String value)
Detect the style then parse the value to return a duration.static Duration
detectAndParse(String value, ChronoUnit unit)
Detect the style then parse the value to return a duration.protected Matcher
matcher(String value)
protected boolean
matches(String value)
Duration
parse(String value)
Parse the given value to a duration.abstract Duration
parse(String value, ChronoUnit unit)
Parse the given value to a duration.String
print(Duration value)
Print the specified duration.abstract String
print(Duration value, ChronoUnit unit)
Print the specified duration using the given unit.static DurationStyle
valueOf(String name)
Returns the enum constant of this type with the specified name.static DurationStyle[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
Enum Constant Detail
SIMPLE
public static final DurationStyle SIMPLE
Simple formatting, for example '1s'.
ISO8601
public static final DurationStyle ISO8601
ISO-8601 formatting.
Method Detail
values
public static DurationStyle[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (DurationStyle c : DurationStyle.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
valueOf
public static DurationStyle valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified nameNullPointerException
- if the argument is null
parse
public Duration parse(String value)
Parse the given value to a duration.- Parameters:
value
- the value to parse- Returns:
- a duration
parse
public abstract Duration parse(String value, ChronoUnit unit)
Parse the given value to a duration.- Parameters:
value
- the value to parseunit
- the duration unit to use if the value doesn't specify one (null
will default to ms)- Returns:
- a duration
print
public String print(Duration value)
Print the specified duration.- Parameters:
value
- the value to print- Returns:
- the printed result
print
public abstract String print(Duration value, ChronoUnit unit)
Print the specified duration using the given unit.- Parameters:
value
- the value to printunit
- the value to use for printing- Returns:
- the printed result
detectAndParse
public static Duration detectAndParse(String value)
Detect the style then parse the value to return a duration.- Parameters:
value
- the value to parse- Returns:
- the parsed duration
- Throws:
IllegalStateException
- if the value is not a known style or cannot be parsed
detectAndParse
public static Duration detectAndParse(String value, ChronoUnit unit)
Detect the style then parse the value to return a duration.- Parameters:
value
- the value to parseunit
- the duration unit to use if the value doesn't specify one (null
will default to ms)- Returns:
- the parsed duration
- Throws:
IllegalStateException
- if the value is not a known style or cannot be parsed
detect
public static DurationStyle detect(String value)
Detect the style from the given source value.- Parameters:
value
- the source value- Returns:
- the duration style
- Throws:
IllegalStateException
- if the value is not a known style