|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.siefkes.nlstego.util.Util
public final class Util
A static class that provides some utility constands and methods. No instances of this class can be created, only the static members should be used.
| Field Summary | |
|---|---|
static char |
FALSE_CHAR
Character representing the boolean value false: '-'. |
static String |
LINE_SEPARATOR
The line separator on the current operating system ("\n" on Unix). |
static String |
NAN
String recognized as Not-a-Number when parsing floating-point numbers: "NaN" (ignoring case). |
static char |
TRUE_CHAR
Character representing the boolean value true: '+'. |
| Method Summary | |
|---|---|
static boolean |
asBoolean(char character)
Converts a character into a boolean primitive. |
static boolean |
asBoolean(String str)
Converts a String into a boolean primitive. |
static char |
asChar(String str)
Converts a String into a char primitive. |
static double |
asDouble(String str)
Converts a String into a double primitive using the Double.parseDouble(java.lang.String) method. |
static float |
asFloat(String str)
Converts a String into a float primitive using the Float.parseFloat(java.lang.String) method. |
static int |
asInt(String str)
Converts a String into an integer primitive using the Integer.decode(java.lang.String) method. |
static long |
asLong(String str)
Converts a String into a long primitive using the Long.decode(java.lang.String) method. |
static short |
asShort(String str)
Converts a String into a short primitive using the Short.decode(java.lang.String) method. |
static List<String> |
configureFromArgs(Configuration config,
String[] args)
Modifies a configuration from -key[=value]
pairs in a string array. |
static String |
formatDouble(double number)
Formats a double, using three decimal digits. |
static String |
formatDouble(double number,
int digits)
Formats a double, using the specified number of decimal digits. |
static String |
formatPercentage(double number)
Formats a number as a percentage, using three decimal digits. |
static String |
formatPercentage(double number,
int digits)
Formats a number as a percentage, using the specified number of decimal digits. |
static Configuration |
loadConfiguration(String baseName)
Loads a configuration in PropertiesConfiguration from the
baseName.cfg in the user's home directory, if it
exists and is a readable file. |
static void |
modifyConfigProperty(Configuration config,
String keyValue)
Modifies a configuration property, parsing a key[=value]
pair. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String LINE_SEPARATOR
public static final String NAN
public static final char TRUE_CHAR
true: '+'.
public static final char FALSE_CHAR
false: '-'.
| Method Detail |
|---|
public static boolean asBoolean(char character)
throws IllegalArgumentException
TRUE_CHAR is
converted to true; FALSE_CHAR is
converted to false. An exception is thrown in all other
cases.
character - the character to convert
IllegalArgumentException - if the character cannot be converted
into a boolean
public static boolean asBoolean(String str)
throws IllegalArgumentException
BooleanUtils.toBooleanObject(java.lang.String), i.e.
The strings "true", "on", and "yes" are accepted for a true
value; "false", "off", and "no" are accepted for false;
case and surrounding whitespace are ignored. If the string contains a
single character, the result of asBoolean(char) is returned.
An exception is thrown for all other strings.
If the specified String is null, false
is returned.
str - the String to check
IllegalArgumentException - if the String cannot be parsed as a
boolean
public static char asChar(String str)
throws IndexOutOfBoundsException
If the specified String is null,
Character.MIN_VALUE (the smallest character value) is returned.
str - the String to check
IndexOutOfBoundsException - if the String is empty (after trimming
outer whitespace)
public static double asDouble(String str)
throws NumberFormatException
Double.parseDouble(java.lang.String) method.
If the trimmed String to equal to NAN (ignoring case),
Double.NaN is returned.
If the specified String is null, -1.0 is returned.
str - the String to check
NumberFormatException - if the String does not contain a parsable
double
public static float asFloat(String str)
throws NumberFormatException
Float.parseFloat(java.lang.String) method.
If the trimmed String to equal to NAN (ignoring case),
Float.NaN is returned.
If the specified String is null, -1 is returned.
str - the String to check
NumberFormatException - if the String does not contain a parsable
float
public static int asInt(String str)
throws NumberFormatException
Integer.decode(java.lang.String) method.
If the specified String is null, -1 is returned.
str - the String to check
NumberFormatException - if the String does not contain a parsable
int
public static long asLong(String str)
throws NumberFormatException
Long.decode(java.lang.String) method.
If the specified String is null, -1 is returned.
str - the String to check
NumberFormatException - if the String does not contain a parsable
long
public static short asShort(String str)
throws NumberFormatException
Short.decode(java.lang.String) method.
If the specified String is null, -1 is returned.
str - the String to check
NumberFormatException - if the String does not contain a parsable
short
public static List<String> configureFromArgs(Configuration config,
String[] args)
throws IllegalArgumentException
-key[=value]
pairs in a string array. Delegates to
modifyConfigProperty(Configuration, String) for each array
element starting with "-". Other array elements are collected and
returned.
config - the configuration to modifyargs - the array of strings to parse
IllegalArgumentException - if one of the
[+|-]key[=value] pairs doesn't contain a key ("=" is second
printable character)public static String formatDouble(double number)
Created (21.01.2002 12:09:23) by Christian Siefkes.
number - the double to format
public static String formatDouble(double number,
int digits)
Created (21.01.2002 12:11:06) by Christian Siefkes.
number - the double to formatdigits - how many decimal digits to use
public static String formatPercentage(double number)
Created (21.01.2002 12:09:23) by Christian Siefkes.
number - the double to format
public static String formatPercentage(double number,
int digits)
Created (21.01.2002 12:11:06) by Christian Siefkes.
number - the double to formatdigits - how many decimal digits to use
public static Configuration loadConfiguration(String baseName)
throws ConfigurationException
PropertiesConfiguration from the
baseName.cfg in the user's home directory, if it
exists and is a readable file. Otherwise an empty configuration will
be returned. The file is assumed to use the platform's default
character set.
baseName - the base name of the configuration
ConfigurationException - if an error occurs while loading the
configuraiton
public static void modifyConfigProperty(Configuration config,
String keyValue)
throws IllegalArgumentException
key[=value]
pair. Both key and value are trimmed. Boolean.TRUE is used as
default value if the =value part is omitted.
If "=" is the last character (empty value), the property is removed from
the configuration
(Configuration.clearProperty(java.lang.String)).
config - the configuration to modifykeyValue - the key=value pair to parse
IllegalArgumentException - if keyValue doesn't contain
a key ("=" is first character)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||