Class Formatting
- java.lang.Object
-
- com.oracle.coherence.common.base.Formatting
-
public abstract class Formatting extends Object
Class for providing formatting functionality for various types.- Since:
- 20.06
- Author:
- cp 2000.08.02
-
-
Field Summary
Fields Modifier and Type Field Description static int[]
CRC32_TABLE
static char[]
HEX
Hex digits.static int
POWER_0
Integer constant representing an exponent of zero.static int
POWER_G
Integer constant representing an exponent of 30.static int
POWER_K
Integer constant representing an exponent of 10.static int
POWER_M
Integer constant representing an exponent of 20.static int
POWER_T
Integer constant representing an exponent of 40.
-
Constructor Summary
Constructors Constructor Description Formatting()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
breakLines(String sText, int nWidth, String sIndent)
Breaks the specified string into a multi-line string.static String
breakLines(String sText, int nWidth, String sIndent, boolean fFirstLine)
Breaks the specified string into a multi-line string.static String
capitalize(String s)
Capitalize a string.static int
decimalValue(char ch)
Returns the integer value of a decimal digit.static String
dup(char ch, int cch)
Create a String of the specified length containing the specified character.static String
dup(String s, int c)
Create a String which is a duplicate of the specified number of the passed String.static int
escape(char ch, char[] ach, int of)
Format a char to a printable escape if necessary, putting the result into the passed array.static String
formatDateTime(long ldt)
Format a long value into a human readable date/time string.static int
getMaxDecDigits(int n)
Calculate the number of decimal digits needed to display the passed value.static int
getMaxHexDigits(int n)
Calculate the number of hex digits needed to display the passed value.static int
hexValue(char ch)
Returns the integer value of a hexadecimal digit.static String
indentString(String sText, String sIndent)
Indent the passed multi-line string.static String
indentString(String sText, String sIndent, boolean fFirstLine)
Textually indent the passed multi-line string.static boolean
isDecimal(char ch)
Returns true if the passed character is a decimal digit.static boolean
isHex(char ch)
Returns true if the passed character is a hexadecimal digit.static boolean
isOctal(char ch)
Returns true if the passed character is an octal digit.static int
octalValue(char ch)
Returns the integer value of an octal digit.static long
pad(long lMin, long lMultiple)
Return the smallest value that is not less than the first argument and is a multiple of the second argument.static long
parseBandwidth(String s)
Parse the given string representation of a number of bytes per second.static long
parseBandwidth(String s, int nDefaultPower)
Parse the given string representation of a number of bytes per second.static String[]
parseDelimitedString(String s, char chDelim)
Parse a character-delimited String into an array of Strings.static int
parseHex(char ch)
Return the integer value of a hexadecimal digit.static byte[]
parseHex(String s)
Parse the passed String of hexadecimal characters into a binary value.static long
parseMemorySize(String s)
Parse the given string representation of a number of bytes.static long
parseMemorySize(String s, int nDefaultPower)
Parse the given string representation of a number of bytes.static float
parsePercentage(String s)
Parse the given string representation of a percentage value and return its value as a float in the inclusive range of 0.0 and 1.0.static long
parseTime(String s)
Parse the given string representation of a time duration and return its value as a number of milliseconds.static long
parseTime(String s, int nDefaultUnit)
Parse the given string representation of a time duration and return its value as a number of milliseconds.static long
parseTimeNanos(String s)
Parse the given string representation of a time duration and return its value as a number of nanoseconds.static long
parseTimeNanos(String s, int nDefaultUnit)
Parse the given string representation of a time duration and return its value as a number of nanoseconds.static String
replace(String sText, String sFrom, String sTo)
Replace all occurrences of the specified substring in the specified string.static String
toBandwidthString(long cbps)
Format the passed bandwidth (in bytes per second) as a String that can be parsed byparseBandwidth(java.lang.String)
such that cb==parseBandwidth(toBandwidthString(cb)) holds true for all legal values of cbps.static String
toBandwidthString(long cbps, boolean fExact)
Format the passed bandwidth (in bytes per second) as a String.static String
toCharEscape(char ch)
Format a char to a printable escape if necessary.static int
toCrc(byte[] ab)
Calculate a CRC32 value from a byte array.static int
toCrc(byte[] ab, int of, int cb)
Calculate a CRC32 value from a portion of a byte array.static int
toCrc(byte[] ab, int of, int cb, int nCrc)
Continue to calculate a CRC32 value from a portion of a byte array.static int
toCrc(ByteSequence seq)
Calculate a CRC32 value from a ByteSequence.static int
toCrc(ByteSequence seq, int of, int cb, int nCrc)
Continue to calculate a CRC32 value from a portion of a ByteSequence .static String
toDecString(int n, int cDigits)
Format the passed non-negative integer as a fixed-length decimal string.static String
toDelimitedString(int[] an, String sDelim)
Format the content of the passed integer array as a delimited string.static String
toDelimitedString(long[] al, String sDelim)
Format the content of the passed long array as a delimited string.static String
toDelimitedString(Object[] ao, String sDelim)
Format the content of the passed Object array as a delimited string.static String
toDelimitedString(Iterator<?> iter, String sDelim)
Format the content of the passed Iterator as a delimited string.static String
toHex(byte[] ab)
Convert a byte array to the hex sequence of 2 hex digits per byte.static String
toHex(int b)
Convert a byte to the hex sequence of 2 hex digits.static String
toHexDump(byte[] ab, int cBytesPerLine)
Convert a byte array to a hex dump.static String
toHexEscape(byte b)
Convert a byte to a hex sequence of '0' + 'x' + 2 hex digits.static String
toHexEscape(byte[] ab)
Convert a byte array to a hex sequence of '0' + 'x' + 2 hex digits per byte.static String
toHexEscape(byte[] ab, int of, int cb)
Convert a byte array to a hex sequence of '0' + 'x' + 2 hex digits per byte.static String
toHexEscape(ByteSequence seq, int of, int cb)
Convert a ByteSequence to a hex sequence of '0' + 'x' + 2 hex digits per byte.static String
toHexString(int n, int cDigits)
Format the passed integer as a fixed-length hex string.static String
toMemorySizeString(long cb)
Format the passed memory size (in bytes) as a String that can be parsed byparseMemorySize(java.lang.String)
such that cb==parseMemorySize(toMemorySizeString(cb)) holds true for all legal values of cb.static String
toMemorySizeString(long cb, boolean fExact)
Format the passed memory size (in bytes) as a String.static String
toQuotedCharEscape(char ch)
Format a char to a printable escape if necessary as it would appear (quoted) in Java source code.static String
toQuotedStringEscape(String s)
Format a String as it would appear (quoted) in Java source code, escaping characters as necessary.static String
toSqlString(String s)
Escapes the string for SQL.static String
toString(double dfl, int cMinDigits)
Format a double value as a String.static String
toStringEscape(String s)
Format a String escaping characters as necessary.static String
toUnicodeEscape(char ch)
Format a Unicode character to the Unicode escape sequence of '\' + 'u' + 4 hex digits.static String
truncateString(String s, int cLimit)
Truncate a string to the specified character count.static String
truncateString(Collection<?> coll, int cLimit)
Provide a string representation of elements within the collection until the concatenated string length exceedscLimit
.
-
-
-
Field Detail
-
HEX
public static final char[] HEX
Hex digits.
-
CRC32_TABLE
public static final int[] CRC32_TABLE
-
POWER_0
public static final int POWER_0
Integer constant representing an exponent of zero.
-
POWER_K
public static final int POWER_K
Integer constant representing an exponent of 10.
-
POWER_M
public static final int POWER_M
Integer constant representing an exponent of 20.
-
POWER_G
public static final int POWER_G
Integer constant representing an exponent of 30.
-
POWER_T
public static final int POWER_T
Integer constant representing an exponent of 40.
-
-
Method Detail
-
toString
public static String toString(double dfl, int cMinDigits)
Format a double value as a String.- Parameters:
dfl
- a double valuecMinDigits
- the minimum number of digits of precision to display- Returns:
- the double value formatted as a String
-
toUnicodeEscape
public static String toUnicodeEscape(char ch)
Format a Unicode character to the Unicode escape sequence of '\' + 'u' + 4 hex digits.- Parameters:
ch
- the character- Returns:
- the Unicode escape sequence
-
toCharEscape
public static String toCharEscape(char ch)
Format a char to a printable escape if necessary.- Parameters:
ch
- the char- Returns:
- a printable String representing the passed char
-
toQuotedCharEscape
public static String toQuotedCharEscape(char ch)
Format a char to a printable escape if necessary as it would appear (quoted) in Java source code.This is a replacement for Text.printableChar().
- Parameters:
ch
- the character- Returns:
- a printable String in single quotes representing the passed char
-
toStringEscape
public static String toStringEscape(String s)
Format a String escaping characters as necessary.- Parameters:
s
- the String- Returns:
- a printable String representing the passed String
-
toQuotedStringEscape
public static String toQuotedStringEscape(String s)
Format a String as it would appear (quoted) in Java source code, escaping characters as necessary.This is a replacement for Text.printableString().
- Parameters:
s
- the String- Returns:
- a printable String in double quotes representing the passed String
-
escape
public static int escape(char ch, char[] ach, int of)
Format a char to a printable escape if necessary, putting the result into the passed array. The array must be large enough to accept six characters.- Parameters:
ch
- the character to formatach
- the array of characters to format intoof
- the offset in the array to format at- Returns:
- the number of characters used to format the char
-
toSqlString
public static String toSqlString(String s)
Escapes the string for SQL.- Returns:
- the string quoted for SQL and escaped as necessary
-
indentString
public static String indentString(String sText, String sIndent)
Indent the passed multi-line string.- Parameters:
sText
- the string to indentsIndent
- a string used to indent each line- Returns:
- the string, indented
-
indentString
public static String indentString(String sText, String sIndent, boolean fFirstLine)
Textually indent the passed multi-line string.- Parameters:
sText
- the string to indentsIndent
- a string used to indent each linefFirstLine
- true indents all lines; false indents all but the first- Returns:
- the string, indented
-
breakLines
public static String breakLines(String sText, int nWidth, String sIndent)
Breaks the specified string into a multi-line string.- Parameters:
sText
- the string to breaknWidth
- the max width of resulting lines (including the indent)sIndent
- a string used to indent each line- Returns:
- the string, broken and indented
-
breakLines
public static String breakLines(String sText, int nWidth, String sIndent, boolean fFirstLine)
Breaks the specified string into a multi-line string.- Parameters:
sText
- the string to breaknWidth
- the max width of resulting lines (including the indent)sIndent
- a string used to indent each linefFirstLine
- if true indents all lines; otherwise indents all but the first- Returns:
- the string, broken and indented
-
dup
public static String dup(char ch, int cch)
Create a String of the specified length containing the specified character.- Parameters:
ch
- the character to fill the String withcch
- the length of the String- Returns:
- a String containing the character
repeated times
-
dup
public static String dup(String s, int c)
Create a String which is a duplicate of the specified number of the passed String.- Parameters:
s
- the String to fill the new String withc
- the number of duplicates to put into the new String- Returns:
- a String containing the String s repeated c times
-
replace
public static String replace(String sText, String sFrom, String sTo)
Replace all occurrences of the specified substring in the specified string.- Parameters:
sText
- string to changesFrom
- pattern to change fromsTo
- pattern to change to- Returns:
- modified string
-
parseDelimitedString
public static String[] parseDelimitedString(String s, char chDelim)
Parse a character-delimited String into an array of Strings.- Parameters:
s
- character-delimited String to parsechDelim
- character delimiter- Returns:
- an array of String objects parsed from the passed String
-
toDelimitedString
public static String toDelimitedString(int[] an, String sDelim)
Format the content of the passed integer array as a delimited string.- Parameters:
an
- the arraysDelim
- the delimiter- Returns:
- the formatted string
-
toDelimitedString
public static String toDelimitedString(long[] al, String sDelim)
Format the content of the passed long array as a delimited string.- Parameters:
al
- the arraysDelim
- the delimiter- Returns:
- the formatted string
-
toDelimitedString
public static String toDelimitedString(Object[] ao, String sDelim)
Format the content of the passed Object array as a delimited string.- Parameters:
ao
- the arraysDelim
- the delimiter- Returns:
- the formatted string
-
toDelimitedString
public static String toDelimitedString(Iterator<?> iter, String sDelim)
Format the content of the passed Iterator as a delimited string.- Parameters:
iter
- the IteratorsDelim
- the delimiter- Returns:
- the formatted string
-
capitalize
public static String capitalize(String s)
Capitalize a string.- Parameters:
s
- the string to capitalize- Returns:
- the capitalized string
-
truncateString
public static String truncateString(String s, int cLimit)
Truncate a string to the specified character count.- Parameters:
s
- the String to be truncatedcLimit
- expected character count- Returns:
- the truncated String
-
truncateString
public static String truncateString(Collection<?> coll, int cLimit)
Provide a string representation of elements within the collection until the concatenated string length exceedscLimit
.- Parameters:
coll
- the collection of elements to describecLimit
- expected character count- Returns:
- the truncated string representation of the provided collection
-
isHex
public static boolean isHex(char ch)
Returns true if the passed character is a hexadecimal digit.- Parameters:
ch
- The character to check
-
hexValue
public static int hexValue(char ch)
Returns the integer value of a hexadecimal digit.- Parameters:
ch
- The character to convert
-
getMaxHexDigits
public static int getMaxHexDigits(int n)
Calculate the number of hex digits needed to display the passed value.- Parameters:
n
- the value- Returns:
- the number of hex digits needed to display the value
-
toHexString
public static String toHexString(int n, int cDigits)
Format the passed integer as a fixed-length hex string.- Parameters:
n
- the valuecDigits
- the length of the resulting hex string- Returns:
- the hex value formatted to the specified length string
-
toHex
public static String toHex(int b)
Convert a byte to the hex sequence of 2 hex digits.- Parameters:
b
- the byte- Returns:
- the hex sequence
-
toHex
public static String toHex(byte[] ab)
Convert a byte array to the hex sequence of 2 hex digits per byte.This is a replacement for Text.toString(char[]).
- Parameters:
ab
- the byte array- Returns:
- the hex sequence
-
toHexEscape
public static String toHexEscape(byte b)
Convert a byte to a hex sequence of '0' + 'x' + 2 hex digits.- Parameters:
b
- the byte- Returns:
- the hex sequence
-
toHexEscape
public static String toHexEscape(byte[] ab)
Convert a byte array to a hex sequence of '0' + 'x' + 2 hex digits per byte.- Parameters:
ab
- the byte array- Returns:
- the hex sequence
-
toHexEscape
public static String toHexEscape(byte[] ab, int of, int cb)
Convert a byte array to a hex sequence of '0' + 'x' + 2 hex digits per byte.- Parameters:
ab
- the byte arrayof
- the offset into arraycb
- the number of bytes to convert- Returns:
- the hex sequence
-
toHexEscape
public static String toHexEscape(ByteSequence seq, int of, int cb)
Convert a ByteSequence to a hex sequence of '0' + 'x' + 2 hex digits per byte.- Parameters:
seq
- the ByteSequenceof
- the offset into the byte sequencecb
- the number of bytes to convert- Returns:
- the hex sequence
- Since:
- Coherence 3.7
-
toHexDump
public static String toHexDump(byte[] ab, int cBytesPerLine)
Convert a byte array to a hex dump.This is a replacement for Text.toString(byte[] ab, int cBytesPerLine).
- Parameters:
ab
- the byte array to format as a hex stringcBytesPerLine
- the number of bytes to display on a line- Returns:
- a multi-line hex dump
-
parseHex
public static byte[] parseHex(String s)
Parse the passed String of hexadecimal characters into a binary value. This implementation allows the passed String to be prefixed with "0x".- Parameters:
s
- the hex String to evaluate- Returns:
- the byte array value of the passed hex String
-
parseHex
public static int parseHex(char ch)
Return the integer value of a hexadecimal digit.- Parameters:
ch
- the hex character to evaluate- Returns:
- the integer value of the passed hex character
-
isDecimal
public static boolean isDecimal(char ch)
Returns true if the passed character is a decimal digit.- Parameters:
ch
- The character to check
-
decimalValue
public static int decimalValue(char ch)
Returns the integer value of a decimal digit.- Parameters:
ch
- The character to convert
-
getMaxDecDigits
public static int getMaxDecDigits(int n)
Calculate the number of decimal digits needed to display the passed value.- Parameters:
n
- the value- Returns:
- the number of decimal digits needed to display the value
-
toDecString
public static String toDecString(int n, int cDigits)
Format the passed non-negative integer as a fixed-length decimal string.- Parameters:
n
- the valuecDigits
- the length of the resulting decimal string- Returns:
- the decimal value formatted to the specified length string
-
pad
public static long pad(long lMin, long lMultiple)
Return the smallest value that is not less than the first argument and is a multiple of the second argument. Effectively rounds the first argument up to a multiple of the second.- Parameters:
lMin
- the smallest value to returnlMultiple
- the return value will be a multiple of this argument- Returns:
- the smallest multiple of the second argument that is not less than the first
-
isOctal
public static boolean isOctal(char ch)
Returns true if the passed character is an octal digit.- Parameters:
ch
- The character to check
-
octalValue
public static int octalValue(char ch)
Returns the integer value of an octal digit.- Parameters:
ch
- The character to convert
-
parseBandwidth
public static long parseBandwidth(String s)
Parse the given string representation of a number of bytes per second. The supplied string must be in the format:[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[[B|b][P|p][S|s]]?
where the first non-digit (from left to right) indicates the factor with which the preceding decimal value should be multiplied:
- K or k (kilo, 210)
- M or m (mega, 220)
- G or g (giga, 230)
- T or t (tera, 240)
If the string value does not contain a factor, a factor of one is assumed.
The optional last three characters indicate the unit of measure, [b][P|p][S|s] in the case of bits per second and [B][P|p][S|s] in the case of bytes per second. If the string value does not contain a unit, a unit of bits per second is assumed.
- Parameters:
s
- a string with the format: [\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[[B|b][P|p][S|s]]?- Returns:
- the number of bytes per second represented by the given string
-
parseBandwidth
public static long parseBandwidth(String s, int nDefaultPower)
Parse the given string representation of a number of bytes per second. The supplied string must be in the format:[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[[B|b][P|p][S|s]]?
where the first non-digit (from left to right) indicates the factor with which the preceding decimal value should be multiplied:
- K or k (kilo, 210)
- M or m (mega, 220)
- G or g (giga, 230)
- T or t (tera, 240)
If the string value does not contain an explicit or implicit factor, a factor calculated by raising 2 to the given default power is used. The default power can be one of:
The optional last three characters indicate the unit of measure, [b][P|p][S|s] in the case of bits per second and [B][P|p][S|s] in the case of bytes per second. If the string value does not contain a unit, a unit of bits per second is assumed.
- Parameters:
s
- a string with the format: [\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[[B|b][P|p][S|s]]?nDefaultPower
- the exponent used to calculate the factor used in the conversion if one is not implied by the given string- Returns:
- the number of bytes per second represented by the given string
-
toBandwidthString
public static String toBandwidthString(long cbps)
Format the passed bandwidth (in bytes per second) as a String that can be parsed byparseBandwidth(java.lang.String)
such that cb==parseBandwidth(toBandwidthString(cb)) holds true for all legal values of cbps.- Parameters:
cbps
- the number of bytes per second- Returns:
- a String representation of the given bandwidth
-
toBandwidthString
public static String toBandwidthString(long cbps, boolean fExact)
Format the passed bandwidth (in bytes per second) as a String. This method will possibly round the memory size for purposes of producing a more-easily read String value unless the fExact parameters is passed as true; if fExact is true, then cb==parseBandwidth(toBandwidthString(cb, true)) holds true for all legal values of cbps.- Parameters:
cbps
- the number of bytes per secondfExact
- true if the String representation must be exact, or false if it can be an approximation- Returns:
- a String representation of the given bandwidth
-
parseMemorySize
public static long parseMemorySize(String s)
Parse the given string representation of a number of bytes. The supplied string must be in the format:[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[B|b]?
where the first non-digit (from left to right) indicates the factor with which the preceding decimal value should be multiplied:
- K or k (kilo, 210)
- M or m (mega, 220)
- G or g (giga, 230)
- T or t (tera, 240)
If the string value does not contain a factor, a factor of one is assumed.
The optional last character B or b indicates a unit of bytes.
- Parameters:
s
- a string with the format [\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[B|b]?- Returns:
- the number of bytes represented by the given string
-
parseMemorySize
public static long parseMemorySize(String s, int nDefaultPower)
Parse the given string representation of a number of bytes. The supplied string must be in the format:[\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[B|b]?
where the first non-digit (from left to right) indicates the factor with which the preceding decimal value should be multiplied:
- K or k (kilo, 210)
- M or m (mega, 220)
- G or g (giga, 230)
- T or t (tera, 240)
If the string value does not contain an explicit or implicit factor, a factor calculated by raising 2 to the given default power is used. The default power can be one of:
The optional last character B or b indicates a unit of bytes.
- Parameters:
s
- a string with the format [\d]+[[.][\d]+]?[K|k|M|m|G|g|T|t]?[B|b]?nDefaultPower
- the exponent used to calculate the factor used in the conversion if one is not implied by the given string- Returns:
- the number of bytes represented by the given string
-
toMemorySizeString
public static String toMemorySizeString(long cb)
Format the passed memory size (in bytes) as a String that can be parsed byparseMemorySize(java.lang.String)
such that cb==parseMemorySize(toMemorySizeString(cb)) holds true for all legal values of cb.- Parameters:
cb
- the number of bytes of memory- Returns:
- a String representation of the given memory size
-
toMemorySizeString
public static String toMemorySizeString(long cb, boolean fExact)
Format the passed memory size (in bytes) as a String. This method will possibly round the memory size for purposes of producing a more-easily read String value unless the fExact parameters is passed as true; if fExact is true, then cb==parseMemorySize(toMemorySizeString(cb, true)) holds true for all legal values of cb.- Parameters:
cb
- the number of bytes of memoryfExact
- true if the String representation must be exact, or false if it can be an approximation- Returns:
- a String representation of the given memory size
-
parseTime
public static long parseTime(String s)
Parse the given string representation of a time duration and return its value as a number of milliseconds. The supplied string must be in the format:[\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?
where the first non-digits (from left to right) indicate the unit of time duration:
- NS or ns (nanoseconds)
- US or us (microseconds)
- MS or ms (milliseconds)
- S or s (seconds)
- M or m (minutes)
- H or h (hours)
- D or d (days)
If the string value does not contain a unit, a unit of milliseconds is assumed.
- Parameters:
s
- a string with the format [\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?- Returns:
- the number of milliseconds represented by the given string rounded down to the nearest millisecond
- See Also:
parseTimeNanos(String)
-
parseTime
public static long parseTime(String s, int nDefaultUnit)
Parse the given string representation of a time duration and return its value as a number of milliseconds. The supplied string must be in the format:[\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?
where the first non-digits (from left to right) indicate the unit of time duration:
- NS or ns (nanoseconds)
- US or us (microseconds)
- MS or ms (milliseconds)
- S or s (seconds)
- M or m (minutes)
- H or h (hours)
- D or d (days)
If the string value does not contain a unit, the specified default unit is assumed. The default unit can be one of:
- Parameters:
s
- a string with the format [\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?nDefaultUnit
- the unit to use in the conversion to milliseconds if one is not specified in the supplied string- Returns:
- the number of milliseconds represented by the given string rounded down to the nearest millisecond
- See Also:
parseTimeNanos(String, int)
-
parseTimeNanos
public static long parseTimeNanos(String s)
Parse the given string representation of a time duration and return its value as a number of nanoseconds. The supplied string must be in the format:[\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?
where the first non-digits (from left to right) indicate the unit of time duration:
- NS or ns (nanoseconds)
- US or us (microseconds)
- MS or ms (milliseconds)
- S or s (seconds)
- M or m (minutes)
- H or h (hours)
- D or d (days)
If the string value does not contain a unit, a unit of nanoseconds is assumed.
- Parameters:
s
- a string with the format [\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?- Returns:
- the number of nanoseconds represented by the given string rounded down to the nearest nanosecond
-
parseTimeNanos
public static long parseTimeNanos(String s, int nDefaultUnit)
Parse the given string representation of a time duration and return its value as a number of nanoseconds. The supplied string must be in the format:[\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?
where the first non-digits (from left to right) indicate the unit of time duration:
- NS or ns (nanoseconds)
- US or us (microseconds)
- MS or ms (milliseconds)
- S or s (seconds)
- M or m (minutes)
- H or h (hours)
- D or d (days)
If the string value does not contain a unit, the specified default unit is assumed. The default unit can be one of:
- Parameters:
s
- a string with the format [\d]+[[.][\d]+]?[NS|ns|US|us|MS|ms|S|s|M|m|H|h|D|d]?nDefaultUnit
- the unit to use in the conversion to nanoseconds if one is not specified in the supplied string- Returns:
- the number of nanoseconds represented by the given string rounded down to the nearest nanosecond
-
formatDateTime
public static String formatDateTime(long ldt)
Format a long value into a human readable date/time string.- Parameters:
ldt
- a Java long containing a date/time value- Returns:
- a human readable date/time string
-
parsePercentage
public static float parsePercentage(String s)
Parse the given string representation of a percentage value and return its value as a float in the inclusive range of 0.0 and 1.0. The supplied string must be in the format:[\d]+[[.][\d]+]?[%]
where the digits are within the closed interval [0.0, 100.0].
- Parameters:
s
- a string with the format [\d]+[[.][\d]+]?[%]- Returns:
- a float representing the percentage value in the closed interval [0.0, 1.0]
-
toCrc
public static int toCrc(byte[] ab)
Calculate a CRC32 value from a byte array.- Parameters:
ab
- an array of bytes- Returns:
- the 32-bit CRC value
-
toCrc
public static int toCrc(byte[] ab, int of, int cb)
Calculate a CRC32 value from a portion of a byte array.- Parameters:
ab
- an array of bytesof
- the offset into the arraycb
- the number of bytes to evaluate- Returns:
- the 32-bit CRC value
-
toCrc
public static int toCrc(byte[] ab, int of, int cb, int nCrc)
Continue to calculate a CRC32 value from a portion of a byte array.- Parameters:
ab
- an array of bytesof
- the offset into the arraycb
- the number of bytes to evaluatenCrc
- the previous CRC value- Returns:
- the 32-bit CRC value
-
toCrc
public static int toCrc(ByteSequence seq)
Calculate a CRC32 value from a ByteSequence.- Parameters:
seq
- a ByteSequence- Returns:
- the 32-bit CRC value
-
toCrc
public static int toCrc(ByteSequence seq, int of, int cb, int nCrc)
Continue to calculate a CRC32 value from a portion of a ByteSequence .- Parameters:
seq
- a ByteSequenceof
- the offset into the ByteSequencecb
- the number of bytes to evaluatenCrc
- the previous CRC value- Returns:
- the 32-bit CRC value
-
-