Methods Summary |
---|
public static java.lang.String | get(java.lang.String key)Get the value for the given key.
if (key.length() > PROP_NAME_MAX) {
throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
}
return native_get(key);
|
public static java.lang.String | get(java.lang.String key, java.lang.String def)Get the value for the given key.
if (key.length() > PROP_NAME_MAX) {
throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
}
return native_get(key, def);
|
public static boolean | getBoolean(java.lang.String key, boolean def)Get the value for the given key, returned as a boolean.
Values 'n', 'no', '0', 'false' or 'off' are considered false.
Values 'y', 'yes', '1', 'true' or 'on' are considered true.
(case insensitive).
If the key does not exist, or has any other value, then the default
result is returned.
String value = get(key);
// Deal with these quick cases first: not found, 0 and 1
if (value.equals("")) {
return def;
} else if (value.equals("0")) {
return false;
} else if (value.equals("1")) {
return true;
// now for slower (and hopefully less common) cases
} else if (value.equalsIgnoreCase("n") ||
value.equalsIgnoreCase("no") ||
value.equalsIgnoreCase("false") ||
value.equalsIgnoreCase("off")) {
return false;
} else if (value.equalsIgnoreCase("y") ||
value.equalsIgnoreCase("yes") ||
value.equalsIgnoreCase("true") ||
value.equalsIgnoreCase("on")) {
return true;
}
return def;
|
public static int | getInt(java.lang.String key, int def)Get the value for the given key, and return as an integer.
try {
return Integer.parseInt(get(key));
} catch (NumberFormatException e) {
return def;
}
|
public static long | getLong(java.lang.String key, long def)Get the value for the given key, and return as a long.
try {
return Long.parseLong(get(key));
} catch (NumberFormatException e) {
return def;
}
|
private static native java.lang.String | native_get(java.lang.String key)
|
private static native java.lang.String | native_get(java.lang.String key, java.lang.String def)
|
private static native void | native_set(java.lang.String key, java.lang.String def)
|
public static void | set(java.lang.String key, java.lang.String val)Set the value for the given key.
if (key.length() > PROP_NAME_MAX) {
throw new IllegalArgumentException("key.length > " + PROP_NAME_MAX);
}
if (val != null && val.length() > PROP_VALUE_MAX) {
throw new IllegalArgumentException("val.length > " +
PROP_VALUE_MAX);
}
native_set(key, val);
|