|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.evanmclean.evlib.misc.Conv
public final class Conv
Functions to convert strings to numbers, returning default values on errors.
Method Summary | |
---|---|
static long |
sizeToLong(String numstr,
long def)
Converts a string representing a size such as "1.5MB" to a raw value of bytes. |
static double |
toDouble(String str,
double def)
Converts the (trimmed) string to a double. |
static Double |
toDoubleObj(String str,
Double def)
Converts the (trimmed) string to a Double, an empty string translating to null. |
static int |
toInt(String str,
int def)
Converts the (trimmed) string to a integer. |
static long |
toLong(String str,
long def)
Converts the (trimmed) string to a long. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static long sizeToLong(String numstr, long def)
Converts a string representing a size such as "1.5MB" to a raw value of bytes.
Size suffixes follow SI and IEC conventions as can be seen on the table on Wikipedia. So "KB" equals a multiplier of 1000, while "KiB" equals a multiplier of 1024.
The allowed (case-insensitive) multiplier suffixes are:
Name | Suffix | Multiplier | Name | Suffix | Multiplier |
---|---|---|---|---|---|
(none) | 1 | ||||
kilobyte | KB | 103 | kibibyte | KiB | 210 |
megabyte | MB | 106 | mebibyte | MiB | 220 |
gigabyte | GB | 109 | gibibyte | GiB | 230 |
terabyte | TB | 1012 | tebibyte | TiB | 240 |
petabyte | PB | 1015 | pebibyte | PiB | 250 |
exabyte | EB | 1018 | exbibyte | EiB | 260 |
zettabyte | ZB | 1021 | zebibyte | ZiB | 270 |
yottabyte | YB | 1024 | yobibyte | YiB | 280 |
If the final value, converted from a double to a long would be negative, or
greater than Long.MAX_VALUE
then this is considered an error
and the default value is returned.
numstr
- The string to convert.def
- The default value to return in case of an error.
public static double toDouble(String str, double def)
str
- The string to convert.def
- The default to return if the string parameter cannot be converted to
a number.
public static Double toDoubleObj(String str, Double def)
str
- The string to convert.def
- The default to return if the string parameter cannot be converted to
a number.
public static int toInt(String str, int def)
str
- The string to convert.def
- The default to return if the string parameter cannot be converted to
a number.
public static long toLong(String str, long def)
str
- The string to convert.def
- The default to return if the string parameter cannot be converted to
a number.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |