Package adams.core
Class MicroSecondFormat
- java.lang.Object
-
- adams.core.MicroSecondFormat
-
- All Implemented Interfaces:
Serializable
public class MicroSecondFormat extends Object implements Serializable
Formatting class for turning byte amounts into kb, mb, etc.
Format: {t|T}[.N]{u|µ|l|s|m|h|d|w}
- b|B
"t" outputs the amount without thousand separators, "T" includes them. - .N
Prints "N" decimal places - u|µ|m|S|M|H|D|W
Specifies the unit to use: u|µ=microseconds, l=milliseconds, s=seconds, m=minutes, h=hours, d=days, w=weeks
Lower case does not add a specifier like "ms", upper case does.
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MicroSecondFormat.Unit
The available units.
-
Field Summary
Fields Modifier and Type Field Description protected boolean
m_AddUnit
whether to add a unit specifier at the end.protected String
m_Format
the format string.protected int
m_NumDecimals
the number of decimals to use.protected MicroSecondFormat.Unit
m_Unit
the conversion unit.protected boolean
m_UseThousandSeparators
whether to use thousand separators or not.
-
Constructor Summary
Constructors Constructor Description MicroSecondFormat(String format)
Initializes the formatter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
format(double microseconds)
Formats the given microsecond amount according to the format.String
format(long microseconds)
Formats the given microsecond amount according to the format.String
getFormat()
Returns the format being used.static String
insertThousandSeparators(String number)
Inserts thousand separators into the number string (integer or float).boolean
isValid(String format)
Tests the format.protected boolean
parseFormat(String format, boolean justTest)
Parses the format.static String
toBestFit(double microseconds, int decimals)
Turns the number of microseconds in the shortest representation (microsec, millisec, sec, min, ...).static String
toDays(double microseconds, int decimals)
Turns the number of microseconds into days.static String
toHours(double microseconds, int decimals)
Turns the number of microseconds into hours.static String
toMilliSeconds(double microseconds, int decimals)
Turns the number of microseconds into milliseconds.static String
toMinutes(double microseconds, int decimals)
Turns the number of microseconds into minutes.static String
toMixed(double microseconds)
Turns the number of seconds into a mixed representation (1w 2d 3h 4m 5s 6ms 7us).static String
toSeconds(double microseconds, int decimals)
Turns the number of microseconds into seconds.String
toString()
Returns a short string description.static String
toWeeks(double microseconds, int decimals)
Turns the number of microseconds into weeks.
-
-
-
Field Detail
-
m_Format
protected String m_Format
the format string.
-
m_UseThousandSeparators
protected boolean m_UseThousandSeparators
whether to use thousand separators or not.
-
m_NumDecimals
protected int m_NumDecimals
the number of decimals to use.
-
m_Unit
protected MicroSecondFormat.Unit m_Unit
the conversion unit.
-
m_AddUnit
protected boolean m_AddUnit
whether to add a unit specifier at the end.
-
-
Constructor Detail
-
MicroSecondFormat
public MicroSecondFormat(String format)
Initializes the formatter.- Parameters:
format
- the format to use
-
-
Method Detail
-
parseFormat
protected boolean parseFormat(String format, boolean justTest)
Parses the format.- Parameters:
format
- the format to parsejustTest
- if true then parameters derived won't be set
-
isValid
public boolean isValid(String format)
Tests the format.- Parameters:
format
- the format to test- Returns:
- true if valid
-
getFormat
public String getFormat()
Returns the format being used.- Returns:
- the format, null if invalid one provided
-
format
public String format(long microseconds)
Formats the given microsecond amount according to the format.- Parameters:
microseconds
- the amount to format- Returns:
- the formatted amount
-
format
public String format(double microseconds)
Formats the given microsecond amount according to the format.- Parameters:
microseconds
- the amount to format- Returns:
- the formatted amount
-
toString
public String toString()
Returns a short string description.
-
insertThousandSeparators
public static String insertThousandSeparators(String number)
Inserts thousand separators into the number string (integer or float).- Parameters:
number
- the string to inject with separators- Returns:
- the processed string
-
toMilliSeconds
public static String toMilliSeconds(double microseconds, int decimals)
Turns the number of microseconds into milliseconds.- Parameters:
microseconds
- the number of microseconds to formatdecimals
- the number of decimals after the decimal point- Returns:
- the millisecond string
-
toSeconds
public static String toSeconds(double microseconds, int decimals)
Turns the number of microseconds into seconds.- Parameters:
microseconds
- the number of microseconds to formatdecimals
- the number of decimals after the decimal point- Returns:
- the second string
-
toMinutes
public static String toMinutes(double microseconds, int decimals)
Turns the number of microseconds into minutes.- Parameters:
microseconds
- the number of microseconds to formatdecimals
- the number of decimals after the decimal point- Returns:
- the minute string
-
toHours
public static String toHours(double microseconds, int decimals)
Turns the number of microseconds into hours.- Parameters:
microseconds
- the number of microseconds to formatdecimals
- the number of decimals after the decimal point- Returns:
- the hour string
-
toDays
public static String toDays(double microseconds, int decimals)
Turns the number of microseconds into days.- Parameters:
microseconds
- the number of microseconds to formatdecimals
- the number of decimals after the decimal point- Returns:
- the day string
-
toWeeks
public static String toWeeks(double microseconds, int decimals)
Turns the number of microseconds into weeks.- Parameters:
microseconds
- the number of microseconds to formatdecimals
- the number of decimals after the decimal point- Returns:
- the week string
-
toBestFit
public static String toBestFit(double microseconds, int decimals)
Turns the number of microseconds in the shortest representation (microsec, millisec, sec, min, ...).- Parameters:
microseconds
- the microseconds to convertdecimals
- the number of decimals after the decimal point- Returns:
- the optimal number string
-
toMixed
public static String toMixed(double microseconds)
Turns the number of seconds into a mixed representation (1w 2d 3h 4m 5s 6ms 7us).- Parameters:
microseconds
- the seconds to convert- Returns:
- the mixed string
-
-