Package net.obvj.performetrics.util
Enum DurationFormat
- java.lang.Object
-
- java.lang.Enum<DurationFormat>
-
- net.obvj.performetrics.util.DurationFormat
-
- All Implemented Interfaces:
Serializable,Comparable<DurationFormat>
public enum DurationFormat extends Enum<DurationFormat>
Enumerates different duration format styles, each one with particular characteristics.Examples:
- DurationFormat.FULL:
0:00:03.200000000 - DurationFormat.SHORT:
3.200000000 second(s) - DurationFormat.SHORTER:
3.2 second(s) - DurationFormat.ISO_8601:
PT3.2S - DurationFormat.LINUX:
0m3.200s
- Since:
- 2.2.0
- Author:
- oswaldo.bapvic.jr
-
-
Enum Constant Summary
Enum Constants Enum Constant Description FULLFormats a time duration in the following format:H:M:S.ns.ISO_8601Formats a time duration using ISO-8601 seconds-based representation.LINUXFormats a time duration in Linux style, applying the formM'm':S.ms's'.SHORTFormats a time duration in any of the following formats:H:M:S.ns,M:S.ns, orS.ns, always choosing the shortest possible format.SHORTERFormats a time duration in any of the following formats:H:M:S.ns,M:S.ns, orS.ns, always choosing the shortest possible format and suppressing trailing zeros from the nanoseconds part.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringformat(Duration duration, boolean printLegend)Formats a given duration.Durationparse(String string)Parses a textual representation of aDuration.static DurationFormatvalueOf(String name)Returns the enum constant of this type with the specified name.static DurationFormat[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
FULL
public static final DurationFormat FULL
Formats a time duration in the following format:H:M:S.ns. For example:1:59:59.987654321.
-
SHORT
public static final DurationFormat SHORT
Formats a time duration in any of the following formats:H:M:S.ns,M:S.ns, orS.ns, always choosing the shortest possible format.Examples:
0.001000000 second(s)3.200000000 second(s)15:00.005890000 minute(s)
-
SHORTER
public static final DurationFormat SHORTER
Formats a time duration in any of the following formats:H:M:S.ns,M:S.ns, orS.ns, always choosing the shortest possible format and suppressing trailing zeros from the nanoseconds part.Examples:
0.001 second(s)3.2 second(s)15:00.00589 minute(s)
-
ISO_8601
public static final DurationFormat ISO_8601
Formats a time duration using ISO-8601 seconds-based representation.For example:
PT8H6M12.345S, where:Pis the duration designator (referred to as "period"), and is always placed at the beginning of the durationTis the time designator that precedes the time componentsHis the hour designator that follows the value for the number of hoursMis the minute designator that follows the value for the number of minutesSis the second designator that follows the value for the number of seconds
Additional examples:
PT0.001SPT3.2SPT15M0.00589S
Note: The
printLegendflag has no effect in this format style.
-
LINUX
public static final DurationFormat LINUX
Formats a time duration in Linux style, applying the formM'm':S.ms's'.Examples:
0m0.125s0m4.999s3m12.038s
Note: The
printLegendflag has no effect in this format style.- Since:
- 2.4.0
-
-
Method Detail
-
values
public static DurationFormat[] 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 (DurationFormat c : DurationFormat.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static DurationFormat 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
-
format
public String format(Duration duration, boolean printLegend)
Formats a given duration.- Parameters:
duration- theDurationto be formatted, not nullprintLegend- a flag indicating whether or not to include the legend in the generated string- Returns:
- a string representing the specified duration, formatted
- Throws:
NullPointerException- if the specified duration is null
-
parse
public Duration parse(String string)
Parses a textual representation of aDuration.- Parameters:
string- the string to parse, not null- Returns:
- the parsed
Duration, not null - Throws:
NullPointerException- if the specified string is nullIllegalArgumentException- if the string cannot be parsed asDuration- Since:
- 2.4.0
-
-