public class Params extends Object
IllegalArgumentException if validation fails. Also all have a name
parameter used to format exception message; it is injected at message beginning exactly as supplied.
In sample code throws illegal argument exception if file argument is null. Exception message is 'File parameter
is null.'
void method(File file . . . {
Params.notNull(file, "File");
. . .
}
This utility class allows for sub-classing. See js.util for utility sub-classing description.
| Modifier | Constructor and Description |
|---|---|
protected |
Params()
Prevent default constructor synthesis but allow sub-classing.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
belongsTo(File directory,
File parameter,
String name)
Check if file parameter belongs to requested directory.
|
static void |
empty(Collection<?> parameter,
String name)
Test if collection parameter is strictly empty, that is, not null but empty.
|
static void |
empty(String parameter,
String name)
Test if string parameter is strictly empty, that is, not null but empty.
|
static void |
EQ(char parameter,
char expected,
String name)
Test if character parameter has expected value.
|
static void |
EQ(double parameter,
double expected,
String name)
Test if numeric parameter has expected value.
|
static void |
EQ(long parameter,
long expected,
String name)
Test if numeric parameter has expected value.
|
static void |
EQ(String parameter,
String expected,
String name)
Test if string parameter has expected value.
|
static void |
GT(char parameter,
char expected,
String name)
Test if character parameter is strictly greater than given character value.
|
static void |
GT(double parameter,
double value,
String name)
Test if numeric parameter is strictly greater than given threshold value.
|
static void |
GT(long parameter,
long value,
String name)
Test if numeric parameter is strictly greater than given threshold value.
|
static void |
GTE(char parameter,
char value,
String name)
Test if character parameter is greater than or equal to given character value.
|
static void |
GTE(double parameter,
double value,
String name)
Test if numeric parameter is greater than or equal to given threshold value.
|
static void |
GTE(long parameter,
long value,
String name)
Test if numeric parameter is greater than or equal to given threshold value.
|
static void |
isDirectory(File parameter,
String name)
Check if file parameter is an existing directory.
|
static void |
isFalse(boolean condition,
String message)
Test if given boolean condition is false and throw exception if not.
|
static void |
isFile(File parameter,
String name)
Check if file parameter is an existing ordinary file, not a directory.
|
static void |
isKindOf(Type parameter,
Type typeToMatch,
String name)
Test if parameter is of requested type and throw exception if not.
|
static void |
isNumeric(String parameter,
String name)
Check if string parameter is numeric.
|
static void |
isTrue(boolean condition,
String message)
Test if given boolean condition is true and throw exception if not.
|
static void |
LT(char parameter,
char value,
String name)
Test if character parameter is strictly less than given character value.
|
static void |
LT(double parameter,
double value,
String name)
Test if numeric parameter is strictly less than given threshold value.
|
static void |
LT(long parameter,
long value,
String name)
Test if numeric parameter is strictly less than given threshold value.
|
static void |
LTE(char parameter,
char value,
String name)
Test if character parameter is less than or equal to given threshold value.
|
static void |
LTE(double parameter,
double value,
String name)
Test if numeric parameter is less than or equal to given threshold value.
|
static void |
LTE(long parameter,
long value,
String name)
Test if numeric parameter is less than or equal to given threshold value.
|
static void |
notEmpty(String parameter,
String name)
Test if string parameter is strict not empty.
|
static void |
notNull(Object parameter,
String name,
Object... args)
Throw exception if parameter is null.
|
static void |
notNullOrEmpty(File parameter,
String name)
Test if file parameter is not null and has not empty path.
|
static void |
notNullOrEmpty(Object[] parameter,
String name)
Test if array parameter is not null or empty.
|
static void |
notNullOrEmpty(String parameter,
String name)
Test if string parameter is not null or empty.
|
static void |
notZero(double parameter,
String name)
Test if numeric parameter is not zero.
|
static void |
positive(double parameter,
String name)
Test if numeric parameter is positive or zero.
|
static void |
range(double parameter,
double lowEndpoint,
double highEndpoint,
String name)
Test if numeric parameter is in a given range.
|
static void |
size(Collection<?> parameter,
int size,
String name)
Test if given collection size has a specified value.
|
static void |
size(Map<?,?> parameter,
int size,
String name)
Test if given map size has a specified value.
|
static void |
strictPositive(double parameter,
String name)
Test if numeric parameter is strict positive.
|
static void |
zero(double parameter,
String name)
Test if numeric parameter is zero.
|
protected Params()
public static void notNull(Object parameter, String name, Object... args) throws IllegalArgumentException
String.format(String, Object...).parameter - invocation parameter to test,name - parameter name used on exception message,args - optional arguments if name is formatted.IllegalArgumentException - if parameter is null.public static void empty(String parameter, String name)
parameter - invocation string parameter,name - the name of invocation parameter.IllegalArgumentException - if parameter is null or not empty.public static void empty(Collection<?> parameter, String name)
parameter - invocation collection parameter,name - the name of invocation parameter.IllegalArgumentException - if parameter is null or not empty.public static void notEmpty(String parameter, String name) throws IllegalArgumentException
parameter - invocation string parameter,name - the name of invocation parameter.IllegalArgumentException - if parameter is empty.public static void notNullOrEmpty(String parameter, String name) throws IllegalArgumentException
parameter - invocation string parameter,name - the name of invocation parameter.IllegalArgumentException - if parameter is null or empty.public static void notNullOrEmpty(File parameter, String name) throws IllegalArgumentException
parameter - invocation file parameter,name - the name of invocation parameter.IllegalArgumentException - if parameter is null or its path is empty.public static void notNullOrEmpty(Object[] parameter, String name) throws IllegalArgumentException
parameter - invocation array parameter,name - the name of invocation parameter.IllegalArgumentException - if parameter array is null or empty.public static void size(Collection<?> parameter, int size, String name) throws IllegalArgumentException
parameter - invocation collection parameters,size - requested size,name - the name of invocation parameter.IllegalArgumentException - if collection has not requested size.public static void size(Map<?,?> parameter, int size, String name) throws IllegalArgumentException
parameter - invocation map parameters,size - requested size,name - the name of invocation parameter.IllegalArgumentException - if map has not requested size.public static void isNumeric(String parameter, String name)
Strings.isNumeric(String) for numeric definition.parameter - invocation parameter value,name - parameter name.IllegalArgumentException - if parameter is not numeric.public static void isFile(File parameter, String name) throws IllegalArgumentException
parameter - invocation file parameter,name - parameter name.IllegalArgumentException - if parameter file is null or does not exist or is a directory.public static void isDirectory(File parameter, String name) throws IllegalArgumentException
parameter - invocation file parameter,name - parameter name.IllegalArgumentException - if parameter file is null or does not designate an existing directory.public static void belongsTo(File directory, File parameter, String name) throws IllegalArgumentException
directory is ancestor
of parameter file.directory - directory supposed to be ancestor of file parameter,parameter - invocation file parameter,name - parameter name.IllegalArgumentException - if parameter file is outside directory.public static void range(double parameter,
double lowEndpoint,
double highEndpoint,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,lowEndpoint - range lower endpoint,highEndpoint - range higher endpoint,name - the name of invocation parameter.IllegalArgumentException - if parameter is not in range.public static void zero(double parameter,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,name - the name of invocation parameter.IllegalArgumentException - if parameter is not zero.public static void notZero(double parameter,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,name - the name of invocation parameter.IllegalArgumentException - if parameter is zero.public static void positive(double parameter,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,name - the name of invocation parameter.IllegalArgumentException - if parameter is not positive or zero.public static void strictPositive(double parameter,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,name - the name of invocation parameter.IllegalArgumentException - if parameter is not strict positive.public static void EQ(long parameter,
long expected,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,expected - expected value,name - the name of invocation parameter.IllegalArgumentException - if parameter has not expected value.public static void EQ(double parameter,
double expected,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,expected - expected value,name - the name of invocation parameter.IllegalArgumentException - if parameter has not expected value.public static void EQ(String parameter, String expected, String name) throws IllegalArgumentException
parameter - invocation string parameter,expected - expected value,name - the name of invocation parameter.IllegalArgumentException - if parameter has not expected value.public static void EQ(char parameter,
char expected,
String name)
throws IllegalArgumentException
parameter - invocation character parameter,expected - expected value,name - the name of invocation parameter.IllegalArgumentException - if parameter has not expected value.public static void GT(long parameter,
long value,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,value - threshold value,name - the name of invocation parameter.IllegalArgumentException - if parameter is not greater than threshold value.public static void GT(double parameter,
double value,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,value - threshold value,name - the name of invocation parameter.IllegalArgumentException - if parameter is not greater than threshold value.public static void GT(char parameter,
char expected,
String name)
throws IllegalArgumentException
parameter - invocation character parameter,expected - expected character value,name - the name of invocation parameter.IllegalArgumentException - if parameter is not greater than threshold character.public static void GTE(long parameter,
long value,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,value - threshold value,name - the name of invocation parameter.IllegalArgumentException - if parameter is not greater than or equal to threshold value.public static void GTE(double parameter,
double value,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,value - threshold value,name - the name of invocation parameter.IllegalArgumentException - if parameter is not greater than or equal to threshold value.public static void GTE(char parameter,
char value,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,value - character value,name - the name of invocation parameter.IllegalArgumentException - if parameter is not greater than or equal to character value.public static void LT(long parameter,
long value,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,value - threshold value,name - the name of invocation parameter.IllegalArgumentException - if parameter is not less than threshold value.public static void LT(double parameter,
double value,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,value - threshold value,name - the name of invocation parameter.IllegalArgumentException - if parameter is not less than threshold value.public static void LT(char parameter,
char value,
String name)
throws IllegalArgumentException
parameter - invocation character parameter,value - threshold value,name - the name of invocation parameter.IllegalArgumentException - if parameter is not less than character value.public static void LTE(long parameter,
long value,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,value - threshold value,name - the name of invocation parameter.IllegalArgumentException - if parameter is not less than or equal to threshold value.public static void LTE(double parameter,
double value,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,value - threshold value,name - the name of invocation parameter.IllegalArgumentException - if parameter is not less than or equal to threshold value.public static void LTE(char parameter,
char value,
String name)
throws IllegalArgumentException
parameter - invocation numeric parameter,value - character value,name - the name of invocation parameter.IllegalArgumentException - if parameter is not less than or equal to character value.public static void isTrue(boolean condition,
String message)
throws IllegalArgumentException
message parameter.condition - boolean condition to test,message - exception message.IllegalArgumentException - if given condition is false.public static void isFalse(boolean condition,
String message)
throws IllegalArgumentException
message parameter.condition - boolean condition to test,message - exception message.IllegalArgumentException - if given condition is true.public static void isKindOf(Type parameter, Type typeToMatch, String name)
parameter - invocation parameter,typeToMatch - type to match,name - the name of invocation parameter.IllegalArgumentException - if parameter is not of requested type.Copyright © 2018. All rights reserved.