public class Values extends Object
Modifier and Type | Field and Description |
---|---|
private static Pattern |
BYTES_REGEXP |
private static SimpleDateFormat |
DATE_FORMAT |
private static SimpleDateFormat |
DATETIME_FORMAT |
static long |
GB |
static long |
kB |
static long |
MB |
private static SimpleDateFormat |
TIME_FORMAT |
Constructor and Description |
---|
Values() |
Modifier and Type | Method and Description |
---|---|
static String |
formatBytes(Long bytes)
Formats a value using units of bytes, kilobytes, megabytes or gigabytes.
|
static String |
formatBytes(Long bytes,
int decimals)
Formats a value using units of bytes, kilobytes, megabytes or gigabytes.
|
static String |
formatMessage(String message,
Object... parameters)
Insert the values of parameters into a template message.
|
static String |
formatNumber(Float number,
int decimals)
Formats a decimal number with the specified number of decimals.
|
static String |
formatNumber(Float number,
int decimals,
String unit)
Formats a decimal number with the specified number of decimals
and optionally adding a unit.
|
static String |
formatTime(long seconds)
Formats a number of seconds to a more proper time format.
|
static boolean |
getBoolean(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(String value,
boolean defaultValue)
Convert a string to a boolean.
|
static Date[] |
getDate(String[] values,
Formatter<Date> dateFormatter) |
static double |
getDouble(String value)
Convert a string to a double.
|
static Double[] |
getDouble(String[] values)
Convert an array of strings to an array of Double:s.
|
static double |
getDouble(String value,
double defaultValue)
Convert a string to a double.
|
static Double |
getDouble(String value,
Double defaultValue) |
static float |
getFloat(String value)
Convert a string to an float.
|
static Float[] |
getFloat(String[] values)
Convert an array of strings to an array of Float:s.
|
static float |
getFloat(String value,
float defaultValue)
Convert a string to an integer.
|
static Float |
getFloat(String value,
Float defaultValue) |
static int |
getInt(String value)
Convert a string to an integer.
|
static Integer[] |
getInt(String[] values)
Convert an array of strings to an array of Integer:s.
|
static int |
getInt(String value,
int defaultValue)
Convert a string to an integer.
|
static Integer |
getInteger(String value,
Integer defaultValue) |
static long |
getLong(String value)
Convert a string to a long.
|
static Long[] |
getLong(String[] values)
Convert an array of strings to an array of Long:s.
|
static long |
getLong(String value,
long defaultValue)
Convert a string to an long.
|
static Long |
getLong(String value,
Long defaultValue)
Convert a string to an long.
|
static String |
getString(Collection<?> values,
String deliminator,
boolean skipNull) |
static <T> String |
getString(Collection<T> values,
String deliminator,
boolean skipNull,
Formatter<? super T> formatter) |
static String |
getString(String value)
Convert a string to a string, and map NULL to the empty string.
|
static String |
getString(String value,
String defaultValue)
Convert a string to a string.
|
static String |
getStringOrNull(String value)
Convert the empty string ("") to null after removing leading and trailing
whitespace.
|
static Long |
parseBytes(String fBytes,
Long defaultValue)
Parses a string containing the number of bytes formatted as
the
formatBytes(Long) method. |
static <T> String[] |
toStrings(Collection<T> values,
Formatter<T> formatter)
Convert a collection of objects to an array of strings.
|
static String |
trim(String s,
int maxLength)
Trim a string to a maximum length.
|
static String |
trimString(String value,
int maxLength)
Trims long strings to a maximum of
maxLength
characters. |
public static final long GB
public static final long MB
public static final long kB
private static final Pattern BYTES_REGEXP
private static final SimpleDateFormat DATE_FORMAT
private static final SimpleDateFormat TIME_FORMAT
private static final SimpleDateFormat DATETIME_FORMAT
public static final int getInt(String value)
value
- The string to convertpublic static final int getInt(String value, int defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be convertedpublic static final Integer[] getInt(String[] values)
values
- The array of stringspublic static final long getLong(String value)
value
- The string to convertpublic static final long getLong(String value, long defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be convertedpublic static final Long getLong(String value, Long defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be convertedpublic static final Long[] getLong(String[] values)
values
- The array of stringspublic static final float getFloat(String value)
value
- The string to convertpublic static final float getFloat(String value, float defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be convertedpublic static final Float[] getFloat(String[] values)
values
- The array of stringspublic static final double getDouble(String value)
value
- The string to convertpublic static final double getDouble(String value, double defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be convertedpublic static final Double[] getDouble(String[] values)
values
- The array of stringspublic static final String getString(String value)
value
- The string to convertpublic static final String getString(String value, String defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string is nullpublic static final String getStringOrNull(String value)
value
- The string to convertpublic static final String getString(Collection<?> values, String deliminator, boolean skipNull)
public static final <T> String getString(Collection<T> values, String deliminator, boolean skipNull, Formatter<? super T> formatter)
public static final <T> String[] toStrings(Collection<T> values, Formatter<T> formatter)
Formatter.format(Object)
method is used, otherwise
Object.toString()
.values
- Collection to be converted.public static final String trimString(String value, int maxLength)
maxLength
characters.value
- The string to trimpublic static final boolean getBoolean(String value)
value
- The value to convertpublic static final boolean getBoolean(String value, boolean defaultValue)
value
- The value to convertdefaultValue
- The value to return if the string is nullpublic static final String formatNumber(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 String formatNumber(Float number, int decimals, 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 String formatBytes(Long bytes)
bytes
- The value to formatpublic static final String formatBytes(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 Long parseBytes(String fBytes, 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 String formatTime(long seconds)
seconds
- The number of secondspublic static final String formatMessage(String message, 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 String trim(String s, int maxLength)
s
- String to be trimmed.maxLength
- The maximum length the string is allowed to be.