Package org.drasyl.util
Class NumberUtil
java.lang.Object
org.drasyl.util.NumberUtil
Utility class for number-related operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
numberToHumanData
(Number number) Takes aNumber
with bytes and returns it as a formatted SI (metric) multiple-byte number.static String
numberToHumanData
(Number number, short precision) Takes aNumber
with bytes and returns it as a formatted SI (metric) multiple-byte number.static String
numberToHumanData
(Number number, short precision, Locale locale) Takes aNumber
with bytes and returns it as a formatted SI (metric) multiple-byte number.static String
numberToHumanData
(Number number, Locale locale) Takes aNumber
with bytes and returns it as a formatted SI (metric) multiple-byte number.static String
numberToHumanDataRate
(Number number) Takes aNumber
with bytes and returns it as a formatted SI (metric) data-rate.static String
numberToHumanDataRate
(Number number, short precision) Takes aNumber
with bytes and returns it as a formatted SI (metric) data-rate.static String
numberToHumanDataRate
(Number number, short precision, Locale locale) Takes aNumber
with bytes and returns it as a formatted SI (metric) data-rate.static String
numberToHumanDataRate
(Number number, Locale locale) Takes aNumber
with bytes and returns it as a formatted SI (metric) data-rate.
-
Method Details
-
numberToHumanData
Takes aNumber
with bytes and returns it as a formatted SI (metric) multiple-byte number.Inspired by https://stackoverflow.com/a/3758880/1074188.
- Parameters:
number
- number containing size in bytesprecision
- Sets the precision of the number. Value -1 has a special meaning here: an absolute formatted number less then 10 results in precision 2; an absolute formatted number less then 100 results in precision 1; all other absolute formatted numbers result in precision 0locale
- Thelocale
to apply during formatting. Iflocale
isnull
then no localization is applied.- Returns:
- the formatted SI (metric) multiple-byte number
- Throws:
IllegalArgumentException
- if precision is less than-1
-
numberToHumanData
Takes aNumber
with bytes and returns it as a formatted SI (metric) multiple-byte number.- Parameters:
number
- number containing size in bytesprecision
- Sets the precision of the number. Value -1 has a special meaning here: an absolute formatted number less then 10 results in precision 2; an absolute formatted number less then 100 results in precision 1; all other absolute formatted numbers result in precision 0- Returns:
- the formatted SI (metric) multiple-byte number
- Throws:
IllegalArgumentException
- if precision is less than-1
-
numberToHumanData
Takes aNumber
with bytes and returns it as a formatted SI (metric) multiple-byte number.- Parameters:
number
- number containing size in byteslocale
- Thelocale
to apply during formatting. Iflocale
isnull
then no localization is applied.- Returns:
- the formatted SI (metric) multiple-byte number
- Throws:
IllegalArgumentException
- if precision is less than-1
-
numberToHumanData
Takes aNumber
with bytes and returns it as a formatted SI (metric) multiple-byte number.- Parameters:
number
- number containing size in bytes- Returns:
- the formatted SI (metric) multiple-byte number
- Throws:
IllegalArgumentException
- if precision is less than-1
-
numberToHumanDataRate
Takes aNumber
with bytes and returns it as a formatted SI (metric) data-rate.Inspired by https://stackoverflow.com/a/3758880/1074188.
- Parameters:
number
- number containing size in bytesprecision
- Sets the precision of the number. Value -1 has a special meaning here: an absolute formatted number less then 10 results in precision 2; an absolute formatted number less then 100 results in precision 1; all other absolute formatted numbers result in precision 0locale
- Thelocale
to apply during formatting. Iflocale
isnull
then no localization is applied.- Returns:
- the formatted SI (metric) data-rate
- Throws:
IllegalArgumentException
- if precision is less than-1
-
numberToHumanDataRate
Takes aNumber
with bytes and returns it as a formatted SI (metric) data-rate.- Parameters:
number
- number containing size in bytesprecision
- Sets the precision of the number. Value -1 has a special meaning here: an absolute formatted number less then 10 results in precision 2; an absolute formatted number less then 100 results in precision 1; all other absolute formatted numbers result in precision 0- Returns:
- the formatted SI (metric) data-rate
- Throws:
IllegalArgumentException
- if precision is less than-1
-
numberToHumanDataRate
Takes aNumber
with bytes and returns it as a formatted SI (metric) data-rate.- Parameters:
number
- number containing size in byteslocale
- Thelocale
to apply during formatting. Iflocale
isnull
then no localization is applied.- Returns:
- the formatted SI (metric) data-rate
- Throws:
IllegalArgumentException
- if precision is less than-1
-
numberToHumanDataRate
Takes aNumber
with bytes and returns it as a formatted SI (metric) data-rate.- Parameters:
number
- number containing size in bytes- Returns:
- the formatted SI (metric) data-rate
- Throws:
IllegalArgumentException
- if precision is less than-1
-