Class FormatUtil
- java.lang.Object
- 
- com.inductiveautomation.ignition.common.FormatUtil
 
- 
 public class FormatUtil extends java.lang.Object
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classFormatUtil.DurationFormatStyle
 - 
Field SummaryFields Modifier and Type Field Description static java.util.regex.PatternEMAIL_PATTERN
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancustomToString(java.lang.Throwable ex)Returns true if the given throwable uses a custom implementation of toString()static java.lang.StringformatByteSize(long numBytes)Formats a size of bytes, appropriately rounding to bytes, kb, mb, etcstatic java.lang.StringformatDateFull(java.util.Date value)Returns a date formated to yyyy-MM-dd hh:mm:ss.Sstatic java.lang.StringformatDuration(long millis)Formats a number of milliseconds as a human-readable string, like "5 hours, 35 minutes, 28 seconds"static java.lang.StringformatDuration(long millis, FormatUtil.DurationFormatStyle style)static java.lang.StringformatDuration(java.util.Locale locale, long millis)Formats a number of milliseconds as a human-readable string, like "5 hours, 35 minutes, 28 seconds"static java.lang.StringformatDuration(java.util.Locale locale, long millis, FormatUtil.DurationFormatStyle style)static java.lang.StringformatDuration(java.util.Locale locale, long millis, FormatUtil.DurationFormatStyle style, boolean alwaysShowMillis)static java.lang.StringformatDurationSince(long millisStart)Shortcut, equivalent to formatDuration(System.currentTimeMillis()-millisStart)static java.lang.StringformatDurationSince(long millisStart, FormatUtil.DurationFormatStyle style)static java.lang.StringformatDurationSinceNano(long nanoStart)Convenience function for using nanoTime for diffs.static java.lang.StringformatSafe(java.lang.String value, java.lang.Object... formatArgs)Performs String.format() on the value, with the provided args, but catches the IllegalFormatException that the function might throw.static java.lang.StringformatSafe(org.apache.log4j.Logger log, java.lang.String value, java.lang.Object... formatArgs)Performs String.format() on the value, with the provided args, but catches the IllegalFormatException that the function might throw.static java.text.DecimalFormatgetCurrencyInstance(java.util.Locale locale)static java.text.DecimalFormatgetDecimalFormat(java.lang.String pattern)Java 9 changed how format symbols are searched, which causes issues for some locales: the symbol returned doesn't match what the user will typically enter from their keyboard.static java.text.DecimalFormatgetDecimalFormat(java.lang.String pattern, java.util.Locale locale)Java 9 changed how format symbols are searched, which causes issues for some locales: the symbol returned doesn't match what the user will typically enter from their keyboard.static java.text.DecimalFormatSymbolsgetDecimalFormatSymbols()Java 9 changed how format symbols are searched, which causes issues for some locales: the symbol returned doesn't match what the user will typically enter from their keyboard.static java.text.DecimalFormatSymbolsgetDecimalFormatSymbols(java.util.Locale locale)Java 9 changed how format symbols are searched, which causes issues for some locales: the symbol returned doesn't match what the user will typically enter from their keyboard.static java.text.DecimalFormatgetIntegerInstance(java.util.Locale locale)static java.text.DecimalFormatgetNumberInstance(java.util.Locale locale)static java.text.DecimalFormatgetPercentInstance(java.util.Locale locale)static java.lang.StringgetStacktraceCompact(java.lang.Throwable ex)static java.lang.StringgetStacktraceFull(java.lang.Throwable ex)static booleanisValidEmailFormat(java.lang.String email)
 
- 
- 
- 
Method Detail- 
formatByteSizepublic static java.lang.String formatByteSize(long numBytes) Formats a size of bytes, appropriately rounding to bytes, kb, mb, etc
 - 
formatDurationSincepublic static java.lang.String formatDurationSince(long millisStart) Shortcut, equivalent to formatDuration(System.currentTimeMillis()-millisStart)
 - 
formatDurationSinceNanopublic static java.lang.String formatDurationSinceNano(long nanoStart) Convenience function for using nanoTime for diffs. Note, however, that internally the value is converted to milliseconds, so this is not useful for formatting sub-millisecond values.
 - 
formatDurationpublic static java.lang.String formatDuration(long millis) Formats a number of milliseconds as a human-readable string, like "5 hours, 35 minutes, 28 seconds"
 - 
formatDurationpublic static java.lang.String formatDuration(java.util.Locale locale, long millis)Formats a number of milliseconds as a human-readable string, like "5 hours, 35 minutes, 28 seconds"
 - 
formatDurationpublic static java.lang.String formatDuration(java.util.Locale locale, long millis, FormatUtil.DurationFormatStyle style)
 - 
formatDurationpublic static java.lang.String formatDuration(java.util.Locale locale, long millis, FormatUtil.DurationFormatStyle style, boolean alwaysShowMillis)
 - 
formatDurationSincepublic static java.lang.String formatDurationSince(long millisStart, FormatUtil.DurationFormatStyle style)
 - 
formatDurationpublic static java.lang.String formatDuration(long millis, FormatUtil.DurationFormatStyle style)
 - 
customToStringpublic static boolean customToString(java.lang.Throwable ex) Returns true if the given throwable uses a custom implementation of toString()
 - 
getStacktraceCompactpublic static java.lang.String getStacktraceCompact(java.lang.Throwable ex) 
 - 
getStacktraceFullpublic static java.lang.String getStacktraceFull(java.lang.Throwable ex) 
 - 
formatDateFullpublic static java.lang.String formatDateFull(java.util.Date value) Returns a date formated to yyyy-MM-dd hh:mm:ss.S
 - 
formatSafepublic static java.lang.String formatSafe(java.lang.String value, java.lang.Object... formatArgs)Performs String.format() on the value, with the provided args, but catches the IllegalFormatException that the function might throw. If formatArgs is null, no operation is performed and the value is returned.
 - 
formatSafepublic static java.lang.String formatSafe(@Nullable org.apache.log4j.Logger log, @Nullable java.lang.String value, @Nullable java.lang.Object... formatArgs)Performs String.format() on the value, with the provided args, but catches the IllegalFormatException that the function might throw. If formatArgs is null, no operation is performed and the value is returned. If the logger parameter is not null, a warning will be logged if an error occurs.
 - 
getDecimalFormatSymbolspublic static java.text.DecimalFormatSymbols getDecimalFormatSymbols() Java 9 changed how format symbols are searched, which causes issues for some locales: the symbol returned doesn't match what the user will typically enter from their keyboard. This overrides to the much more common symbol. This method should _always_ be used instead of getting a instance directly. See FB14239Also, do not hang on to an instance of dfs if the locale could have changed between uses. Get a new set each time. - Returns:
- DecimalFormatSymbols for the default locale, with appropriate changes
 
 - 
getDecimalFormatSymbolspublic static java.text.DecimalFormatSymbols getDecimalFormatSymbols(java.util.Locale locale) Java 9 changed how format symbols are searched, which causes issues for some locales: the symbol returned doesn't match what the user will typically enter from their keyboard. This overrides to the much more common symbol. This method should _always_ be used instead of getting a instance directly. See FB14239- Returns:
- DecimalFormatSymbols for the given locale, with appropriate changes
 
 - 
getDecimalFormatpublic static java.text.DecimalFormat getDecimalFormat(java.lang.String pattern) Java 9 changed how format symbols are searched, which causes issues for some locales: the symbol returned doesn't match what the user will typically enter from their keyboard. This overrides to the much more common symbol. This method should _always_ be used instead of getting a instance directly. See FB14239Also, do not hang on to an instance of DecimalFormat if the locale could have changed between uses. Get a new instance each time. - Parameters:
- pattern- Format pattern
- Returns:
- DecimalFormat with appropriate symbol changes for the default locale. Not null.
 
 - 
getDecimalFormatpublic static java.text.DecimalFormat getDecimalFormat(java.lang.String pattern, java.util.Locale locale)Java 9 changed how format symbols are searched, which causes issues for some locales: the symbol returned doesn't match what the user will typically enter from their keyboard. This overrides to the much more common symbol. This method should _always_ be used instead of getting a instance directly. See FB14239Also, do not hang on to an instance of DecimalFormat if the locale could have changed between uses. Get a new instance each time. - Parameters:
- pattern- Format pattern
- locale- Locale for formatting
- Returns:
- DecimalFormat with appropriate symbol changes for the given locale. Not null.
 
 - 
getIntegerInstancepublic static java.text.DecimalFormat getIntegerInstance(java.util.Locale locale) 
 - 
getCurrencyInstancepublic static java.text.DecimalFormat getCurrencyInstance(java.util.Locale locale) 
 - 
getNumberInstancepublic static java.text.DecimalFormat getNumberInstance(java.util.Locale locale) 
 - 
getPercentInstancepublic static java.text.DecimalFormat getPercentInstance(java.util.Locale locale) 
 - 
isValidEmailFormatpublic static boolean isValidEmailFormat(java.lang.String email) 
 
- 
 
-