public class Values
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.util.regex.Pattern |
BYTES_REGEXP |
private static java.text.SimpleDateFormat |
DATE_FORMAT |
private static java.text.SimpleDateFormat |
DATETIME_FORMAT |
private static long |
GB |
private static long |
kB |
private static long |
MB |
private static java.text.SimpleDateFormat |
TIME_FORMAT |
Constructor and Description |
---|
Values() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
formatBytes(java.lang.Long bytes)
Formats a value using units of bytes, kilobytes, megabytes or gigabytes.
|
static java.lang.String |
formatBytes(java.lang.Long bytes,
int decimals)
Formats a value using units of bytes, kilobytes, megabytes or gigabytes.
|
static java.lang.String |
formatMessage(java.lang.String message,
java.lang.Object... parameters)
Insert the values of parameters into a template message.
|
static java.lang.String |
formatNumber(java.lang.Float number,
int decimals)
Formats a decimal number with the specified number of decimals.
|
static java.lang.String |
formatNumber(java.lang.Float number,
int decimals,
java.lang.String unit)
Formats a decimal number with the specified number of decimals
and optionally adding a unit.
|
static java.lang.String |
formatTime(long seconds)
Formats a number of seconds to a more proper time format.
|
static boolean |
getBoolean(java.lang.String value)
Convert a string to a boolean. '0', 'no', 'false', '' and the null string are
converted to FALSE, all other values are converted to TRUE.
|
static boolean |
getBoolean(java.lang.String value,
boolean defaultValue)
Convert a string to a boolean.
|
static java.util.Date[] |
getDate(java.lang.String[] values,
Formatter<java.util.Date> dateFormatter) |
static double |
getDouble(java.lang.String value)
Convert a string to a double.
|
static java.lang.Double[] |
getDouble(java.lang.String[] values)
Convert an array of strings to an array of Double:s.
|
static double |
getDouble(java.lang.String value,
double defaultValue)
Convert a string to a double.
|
static java.lang.Double |
getDouble(java.lang.String value,
java.lang.Double defaultValue) |
static float |
getFloat(java.lang.String value)
Convert a string to an float.
|
static java.lang.Float[] |
getFloat(java.lang.String[] values)
Convert an array of strings to an array of Float:s.
|
static float |
getFloat(java.lang.String value,
float defaultValue)
Convert a string to an integer.
|
static java.lang.Float |
getFloat(java.lang.String value,
java.lang.Float defaultValue) |
static int |
getInt(java.lang.String value)
Convert a string to an integer.
|
static java.lang.Integer[] |
getInt(java.lang.String[] values)
Convert an array of strings to an array of Integer:s.
|
static int |
getInt(java.lang.String value,
int defaultValue)
Convert a string to an integer.
|
static java.lang.Integer |
getInteger(java.lang.String value,
java.lang.Integer defaultValue) |
static long |
getLong(java.lang.String value)
Convert a string to a long.
|
static java.lang.Long[] |
getLong(java.lang.String[] values)
Convert an array of strings to an array of Long:s.
|
static long |
getLong(java.lang.String value,
long defaultValue)
Convert a string to an long.
|
static java.lang.Long |
getLong(java.lang.String value,
java.lang.Long defaultValue)
Convert a string to an long.
|
static java.lang.String |
getString(java.util.Collection<?> values,
java.lang.String deliminator,
boolean skipNull) |
static <T> java.lang.String |
getString(java.util.Collection<T> values,
java.lang.String deliminator,
boolean skipNull,
Formatter<? super T> formatter) |
static java.lang.String |
getString(java.lang.String value)
Convert a string to a string, and map NULL to the empty string.
|
static java.lang.String |
getString(java.lang.String value,
java.lang.String defaultValue)
Convert a string to a string.
|
static java.lang.String |
getStringOrNull(java.lang.String value)
Convert the empty string ("") to null after removing leading and trailing
whitespace.
|
static java.lang.Long |
parseBytes(java.lang.String fBytes,
java.lang.Long defaultValue)
Parses a string containing the number of bytes formatted as
the
formatBytes(Long) method. |
static <T> java.lang.String[] |
toStrings(java.util.Collection<T> values,
Formatter<T> formatter)
Convert a collection of objects to an array of strings.
|
static java.lang.String |
trim(java.lang.String s,
int maxLength)
Trim a string to a maximum length.
|
static java.lang.String |
trimString(java.lang.String value,
int maxLength)
Trims long strings to a maximum of
maxLength
characters. |
private static final long GB
private static final long MB
private static final long kB
private static final java.util.regex.Pattern BYTES_REGEXP
private static final java.text.SimpleDateFormat DATE_FORMAT
private static final java.text.SimpleDateFormat TIME_FORMAT
private static final java.text.SimpleDateFormat DATETIME_FORMAT
public static final int getInt(java.lang.String value)
value
- The string to convertpublic static final int getInt(java.lang.String value, int defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be convertedpublic static final java.lang.Integer getInteger(java.lang.String value, java.lang.Integer defaultValue)
public static final java.lang.Integer[] getInt(java.lang.String[] values)
values
- The array of stringspublic static final long getLong(java.lang.String value)
value
- The string to convertpublic static final long getLong(java.lang.String value, long defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be convertedpublic static final java.lang.Long getLong(java.lang.String value, java.lang.Long defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be convertedpublic static final java.lang.Long[] getLong(java.lang.String[] values)
values
- The array of stringspublic static final float getFloat(java.lang.String value)
value
- The string to convertpublic static final float getFloat(java.lang.String value, float defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be convertedpublic static final java.lang.Float getFloat(java.lang.String value, java.lang.Float defaultValue)
public static final java.lang.Float[] getFloat(java.lang.String[] values)
values
- The array of stringspublic static final double getDouble(java.lang.String value)
value
- The string to convertpublic static final double getDouble(java.lang.String value, double defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be convertedpublic static final java.lang.Double getDouble(java.lang.String value, java.lang.Double defaultValue)
public static final java.lang.Double[] getDouble(java.lang.String[] values)
values
- The array of stringspublic static final java.lang.String getString(java.lang.String value)
value
- The string to convertpublic static final java.lang.String getString(java.lang.String value, java.lang.String defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string is nullpublic static final java.lang.String getStringOrNull(java.lang.String value)
value
- The string to convertpublic static final java.lang.String getString(java.util.Collection<?> values, java.lang.String deliminator, boolean skipNull)
public static final <T> java.lang.String getString(java.util.Collection<T> values, java.lang.String deliminator, boolean skipNull, Formatter<? super T> formatter)
public static final <T> java.lang.String[] toStrings(java.util.Collection<T> values, Formatter<T> formatter)
Formatter.format(Object)
method is used, otherwise
Object.toString()
.values
- Collection to be converted.formatter
- public static final java.lang.String trimString(java.lang.String value, int maxLength)
maxLength
characters.value
- The string to trimmaxLength
- public static final boolean getBoolean(java.lang.String value)
value
- The value to convertpublic static final boolean getBoolean(java.lang.String value, boolean defaultValue)
value
- The value to convertdefaultValue
- The value to return if the string is nullpublic static final java.util.Date[] getDate(java.lang.String[] values, Formatter<java.util.Date> dateFormatter)
public static final java.lang.String formatNumber(java.lang.Float number, int decimals)
number
- The number to be formatteddecimals
- The number of decimals to display, use a negative value to
display all decimalspublic static final java.lang.String formatNumber(java.lang.Float number, int decimals, java.lang.String unit)
number
- The number to be formatteddecimals
- The number of decimals to display, use a negative value to
display all decimalsunit
- A string that is added to the end of the formatted number, or
null to not add anythingpublic static final java.lang.String formatBytes(java.lang.Long bytes)
bytes
- The value to formatpublic static final java.lang.String formatBytes(java.lang.Long bytes, int decimals)
bytes
- The value to format, -1 = unknowndecimals
- The number of decimals to display in KB, MB, and GB valuespublic static final java.lang.Long parseBytes(java.lang.String fBytes, java.lang.Long defaultValue)
formatBytes(Long)
method.fBytes
- The string containing the value to parsedefaultValue
- This value is returned if the string cannot be parsedpublic static final java.lang.String formatTime(long seconds)
seconds
- The number of secondspublic static final java.lang.String formatMessage(java.lang.String message, java.lang.Object... parameters)
message
- The message template, with placeholders of the
form {1}, {2}, etc. that will be replaced with the values
of the parametersparameters
- The parameters values that will replace the placeholders
in the template messagepublic static java.lang.String trim(java.lang.String s, int maxLength)
s
- String to be trimmed.maxLength
- The maximum length the string is allowed to be.