|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.util.Values
public class Values
This class contains a set of static methods that may be useful for handling strings, ints and other values.
Field Summary | |
---|---|
private static Pattern |
BYTES_REGEXP
|
private static SimpleDateFormat |
DATE_FORMAT
|
private static SimpleDateFormat |
DATETIME_FORMAT
|
private static long |
GB
|
private static long |
kB
|
private static long |
MB
|
private static SimpleDateFormat |
TIME_FORMAT
|
Constructor Summary | |
---|---|
Values()
|
Method Summary | ||
---|---|---|
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 |
formatDate(Date date)
Deprecated. Use a Formatter for dates instead |
|
static String |
formatDateTime(Date datetime)
Deprecated. Use a Formatter for dates instead |
|
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(Date time)
Deprecated. Use a Formatter for dates instead |
|
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 value)
Deprecated. Use a Formatter for dates instead |
|
static Date[] |
getDate(String[] values)
Deprecated. Use a Formatter for dates instead |
|
static Date[] |
getDate(String[] values,
Formatter<Date> dateFormatter)
|
|
static Date |
getDate(String value,
Date defaultValue)
Deprecated. Use a Formatter for dates instead |
|
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
|
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
|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long GB
private static final long MB
private 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
Constructor Detail |
---|
public Values()
Method Detail |
---|
public static final int getInt(String value)
value
- The string to convert
public static final int getInt(String value, int defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be converted
public static final Integer getInteger(String value, Integer defaultValue)
public static final Integer[] getInt(String[] values)
values
- The array of strings
public static final long getLong(String value)
value
- The string to convert
public static final long getLong(String value, long defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be converted
public static final Long getLong(String value, Long defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be converted
public static final Long[] getLong(String[] values)
values
- The array of strings
public static final float getFloat(String value)
value
- The string to convert
public static final float getFloat(String value, float defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be converted
public static final Float getFloat(String value, Float defaultValue)
public static final Float[] getFloat(String[] values)
values
- The array of strings
public static final double getDouble(String value)
value
- The string to convert
public static final double getDouble(String value, double defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string cannot be converted
public static final Double getDouble(String value, Double defaultValue)
public static final Double[] getDouble(String[] values)
values
- The array of strings
public static final String getString(String value)
value
- The string to convert
public static final String getString(String value, String defaultValue)
value
- The string to convertdefaultValue
- The value to return if the string is null
public static final String getStringOrNull(String value)
value
- The string to convert
public 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.formatter
-
public static final String trimString(String value, int maxLength)
maxLength
characters.
value
- The string to trimmaxLength
-
public static final boolean getBoolean(String value)
value
- The value to convert
public static final boolean getBoolean(String value, boolean defaultValue)
value
- The value to convertdefaultValue
- The value to return if the string is null
public static final Date getDate(String value)
Formatter
for dates instead
value
- The value to convert
public static final Date getDate(String value, Date defaultValue)
Formatter
for dates instead
value
- The value to convertdefaultValue
- The value to return if the string can't be converted
public static final Date[] getDate(String[] values)
Formatter
for dates instead
values
- The array of strings
public static final Date[] getDate(String[] values, Formatter<Date> dateFormatter)
public 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 decimals
public 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 anything
public static final String formatBytes(Long bytes)
bytes
- The value to format
public 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 parsed
public static final String formatDate(Date date)
Formatter
for dates instead
date
- The date to format
public static final String formatTime(Date time)
Formatter
for dates instead
time
- The time to format
public static final String formatDateTime(Date datetime)
Formatter
for dates instead
datetime
- The date and time to format
public static final String formatTime(long seconds)
seconds
- The number of seconds
public 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 message
public static String trim(String s, int maxLength)
s
- String to be trimmed.maxLength
- The maximum length the string is allowed to be.
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |