public final class Validate
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static java.util.Map<java.lang.String,java.lang.String> |
argsToMap(java.lang.String[] args,
char delim)
Returns a map with one (key, value) pair for each element
of the specified array.
|
static boolean |
booleanArg(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> map,
boolean isRequired,
boolean defaultValue)
Removes the specified key from the specified map, and returns the
boolean value corresponding to the specified key.
|
static void |
confirmEmptyMap(java.util.Map<java.lang.String,java.lang.String> argsMap)
Checks whether the specified map of key-value pairs is empty.
|
static double |
doubleArg(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> map,
boolean isRequired,
double defaultValue,
double min,
double max)
Removes the specified key from the specified map, and returns the
double value corresponding to the specified key.
|
static float |
floatArg(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> map,
boolean isRequired,
float defaultValue,
float min,
float max)
Removes the specified key from the specified map, and returns the
float value corresponding to the specified key.
|
static java.io.File |
getFile(java.lang.String filename)
Returns a
File object corresponding to the specified filename or
null if filename == null |
static int |
intArg(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> map,
boolean isRequired,
int defaultValue,
int min,
int max)
Removes the specified key from the specified map, and returns the
integer value corresponding to the specified key.
|
static long |
longArg(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> map,
boolean isRequired,
long defaultValue,
long min,
long max)
Removes the specified key from the specified map, and returns the
long value corresponding to the specified key.
|
static java.lang.String |
stringArg(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> map,
boolean isRequired,
java.lang.String defaultValue,
java.lang.String[] possibleValues)
Removes the specified key from the specified map, and returns the
string value corresponding to the specified key.
|
public static java.util.Map<java.lang.String,java.lang.String> argsToMap(java.lang.String[] args,
char delim)
String[]
array must contain the specified delimiter character.
For each array element s, the key is
s.substring(0, s.indexOf(sep))
and the value is s.substring(s.indexOf(sep) + 1).args - a string arraydelim - the delimiter character separating a key and valuejava.lang.IllegalArgumentException - if the specified delimiter character is
not found in any string element in the specified String[] arrayjava.lang.IllegalArgumentException - if the specified delimiter
is the first or last character of each string element in the specified
String[] arrayjava.lang.IllegalArgumentException - if any two elements of the
specified string array have the same keyjava.lang.NullPointerException - if args == null or if
args[j] == null for any j satisfying
(0 <= j && j <= args.length)public static void confirmEmptyMap(java.util.Map<java.lang.String,java.lang.String> argsMap)
argsMap - a map of key-value pairsjava.lang.NullPointerException - if argsMap == nullpublic static java.io.File getFile(java.lang.String filename)
File object corresponding to the specified filename or
null if filename == nullfilename - a filenamenull
if filename == nulljava.lang.IllegalArgumentException - if filename.isEmpty() == truejava.lang.IllegalArgumentException - if filename != null and the
specified file does not exist or is a directorypublic static int intArg(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> map,
boolean isRequired,
int defaultValue,
int min,
int max)
key - the keymap - a map of key-value pairsisRequired - true if the specified key
is required to be in the specified map, and false otherwisedefaultValue - the value that will be returned if
(isRequired == false && map.get(key) == null)min - the minimum valid integer valuemax - the maximum valid integer valuejava.lang.IllegalArgumentException - if min > maxjava.lang.IllegalArgumentException - if
defaultValue < min || defaultValue > maxjava.lang.IllegalArgumentException - if
isRequired == true && map.get(key) == nulljava.lang.IllegalArgumentException - if
map.get(key) != null
&& (Integer.parseInt(map.get(key)) < min
|| Integer.parseInt(map.get(key)) > max)java.lang.NumberFormatException - if map.get(key) != null
and map.get(key) is not a parsable intjava.lang.NullPointerException - if key == null || map == nullpublic static long longArg(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> map,
boolean isRequired,
long defaultValue,
long min,
long max)
key - the keymap - a map of key-value pairsisRequired - true if the specified key
is required to be in the specified map, and false otherwisedefaultValue - the value that will be returned if
(isRequired == false && map.get(key) == null)min - the minimum valid long valuemax - the maximum valid long valuejava.lang.IllegalArgumentException - if min > maxjava.lang.IllegalArgumentException - if
defaultValue < min || defaultValue > maxjava.lang.IllegalArgumentException - if
isRequired == true && map.get(key) == nulljava.lang.IllegalArgumentException - if
map.get(key) != null
&& (Long.parseLong(map.get(key)) < min
|| Long.parseLong(map.get(key)) > max)java.lang.NumberFormatException - if map.get(key) != null
and map.get(key) is not a parsable longjava.lang.NullPointerException - if key == null || map == nullpublic static float floatArg(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> map,
boolean isRequired,
float defaultValue,
float min,
float max)
key - the keymap - a map of key-value pairsisRequired - true if the specified key
is required to be in the specified map, and false otherwisedefaultValue - the value that will be returned if
(isRequired == false && map.get(key) == null)min - the minimum valid float valuemax - the maximum valid float valuejava.lang.IllegalArgumentException - if min > maxjava.lang.IllegalArgumentException - if
defaultValue < min || defaultValue > max
|| Float.isNan(defaultValue)==truejava.lang.IllegalArgumentException - if
isRequired == true && map.get(key) == nulljava.lang.IllegalArgumentException - if
map.get(key) != null
&& (Float.parseFloat(map.get(key)) < min
|| Float.parseFloat(map.get(key)) > max
|| Float.isNaN(map.get(key))java.lang.NumberFormatException - if map.get(key) != null
and map.get(key) is not a parsablbe floatjava.lang.NullPointerException - if key == null || map == nullpublic static double doubleArg(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> map,
boolean isRequired,
double defaultValue,
double min,
double max)
key - the keymap - a map of key-value pairsisRequired - true if the specified key
is required to be in the specified map, and false otherwisedefaultValue - the value that will be returned if
(isRequired == false && map.get(key) == null)min - the minimum valid double valuemax - the maximum valid double valuejava.lang.IllegalArgumentException - if min > maxjava.lang.IllegalArgumentException - if
defaultValue < min || defaultValue > max
|| Double.isNan(defaultValue)==truejava.lang.IllegalArgumentException - if
isRequired == true && map.get(key) == nulljava.lang.IllegalArgumentException - if
map.get(key) != null
&& (Double.parseDouble(map.get(key)) < min
|| Double.parseDouble(map.get(key)) > max
|| Double.isNaN(map.get(key))java.lang.NumberFormatException - if map.get(key) != null
and map.get(key) is not a parsable doublejava.lang.NullPointerException - if key == null || map == nullpublic static boolean booleanArg(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> map,
boolean isRequired,
boolean defaultValue)
v, then true is returned if
(v.equalsIgnoreCase("true") || v.equalsIgnoreCase("t"))
and false is returned if
(v.equalsIgnoreCase("false") || v.equalsIgnoreCase("f")).key - the keymap - a map of key-value pairsisRequired - true if the specified key
is required to be in the specified map, and false otherwisedefaultValue - the value that will be returned if
(isRequired == false && map.get(key) == null)java.lang.IllegalArgumentException - if
isRequired == true && map.get(key) == nulljava.lang.IllegalArgumentException - if the value
(v = map.get(key)) != null &&
false == (v.equalsIgnoreCase("true") || v.equalsIgnoreCase("t")
|| v.equalsIgnoreCase("false") || v.equalsIgnoreCase("f"))
java.lang.NullPointerException - if key == null || map == nullpublic static java.lang.String stringArg(java.lang.String key,
java.util.Map<java.lang.String,java.lang.String> map,
boolean isRequired,
java.lang.String defaultValue,
java.lang.String[] possibleValues)
nullkey - the keymap - a map of key-value pairsisRequired - true if the specified key
is required to be in the specified map, and false otherwisedefaultValue - the value that will be returned if
(isRequired == false && map.get(key) == null)possibleValues - an array of valid string values or null if
the valid values are null and all non-empty strings.java.lang.IllegalArgumentException - if
isRequired == true && map.get(key) == nulljava.lang.IllegalArgumentException - if
possibleValues != null and defaultValue does not
equal any element of the possibleValues arrayjava.lang.IllegalArgumentException - if
possibleValues != null and map.get(key) does not
equal any element of the possibleValues arrayjava.lang.NullPointerException - if key == null || map == null