public class Parameters extends Object
myMethod()
method taking a myParam
parameter whose value must be a Java identifier, you usually check that
by doing:
public void myMethod(String myParam) { if (!Utilities.isJavaIdentifier(myParam)) { throw new IllegalArgumentException("The myParam parameter is not a valid Java identifier"); } }Using this class you can do the same in a simpler way:
public void myMethod(String myParam) { Parameters.javaIdentifier("myParam", myParam); }
Modifier and Type | Method and Description |
---|---|
static void |
javaIdentifier(CharSequence name,
CharSequence value)
Asserts the parameter value is not
null and it is
a Java identifier. |
static void |
javaIdentifierOrNull(CharSequence name,
CharSequence value)
Asserts the parameter value is either
null or a Java
identifier. |
static void |
notEmpty(CharSequence name,
CharSequence value)
Asserts the parameter value is neither
null nor an empty
character sequence. |
static void |
notNull(CharSequence name,
Object value)
Asserts the parameter value is not
null . |
static void |
notWhitespace(CharSequence name,
CharSequence value)
Asserts the parameter value is not
null and it contains
at least one non-whitespace character. |
public static void notNull(CharSequence name, Object value)
null
.
Use java.util.Objects.requireNonNull
in JDK 7.
name
- the parameter name.value
- the parameter value.NullPointerException
- if the parameter value is null
.public static void notEmpty(CharSequence name, CharSequence value)
null
nor an empty
character sequence.name
- the parameter name.value
- the parameter value.NullPointerException
- if the parameter value is null
.IllegalArgumentException
- if the parameter value is an empty
character sequence.public static void notWhitespace(CharSequence name, CharSequence value)
null
and it contains
at least one non-whitespace character. Whitespace is defined as by
String.trim()
.name
- the parameter name.value
- the parameter value.NullPointerException
- if the parameter value is null
.IllegalArgumentException
- if the parameter value does not
contain at least one non-whitespace character.public static void javaIdentifier(CharSequence name, CharSequence value)
null
and it is
a Java identifier.name
- the parameter name.value
- the parameter value.NullPointerException
- if the parameter value is null
.IllegalArgumentException
- if the parameter value is not
a Java identifier.public static void javaIdentifierOrNull(CharSequence name, CharSequence value)
null
or a Java
identifier.name
- the parameter name.value
- the parameter value.IllegalArgumentException
- if the parameter value is neither
null
nor a Java identifier.