public class Parameters
extends java.lang.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 | Description |
|---|---|---|
static void |
javaIdentifier(java.lang.CharSequence name,
java.lang.CharSequence value) |
Asserts the parameter value is not
null and it is
a Java identifier. |
static void |
javaIdentifierOrNull(java.lang.CharSequence name,
java.lang.CharSequence value) |
Asserts the parameter value is either
null or a Java
identifier. |
static void |
notEmpty(java.lang.CharSequence name,
java.lang.CharSequence value) |
Asserts the parameter value is neither
null nor an empty
character sequence. |
static void |
notNull(java.lang.CharSequence name,
java.lang.Object value) |
Asserts the parameter value is not
null. |
static void |
notWhitespace(java.lang.CharSequence name,
java.lang.CharSequence value) |
Asserts the parameter value is not
null and it contains
at least one non-whitespace character. |
public static void notNull(java.lang.CharSequence name,
java.lang.Object value)
null.
Use java.util.Objects.requireNonNull in JDK 7.
name - the parameter name.value - the parameter value.java.lang.NullPointerException - if the parameter value is null.public static void notEmpty(java.lang.CharSequence name,
java.lang.CharSequence value)
null nor an empty
character sequence.name - the parameter name.value - the parameter value.java.lang.NullPointerException - if the parameter value is null.java.lang.IllegalArgumentException - if the parameter value is an empty
character sequence.public static void notWhitespace(java.lang.CharSequence name,
java.lang.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.java.lang.NullPointerException - if the parameter value is null.java.lang.IllegalArgumentException - if the parameter value does not
contain at least one non-whitespace character.public static void javaIdentifier(java.lang.CharSequence name,
java.lang.CharSequence value)
null and it is
a Java identifier.name - the parameter name.value - the parameter value.java.lang.NullPointerException - if the parameter value is null.java.lang.IllegalArgumentException - if the parameter value is not
a Java identifier.public static void javaIdentifierOrNull(java.lang.CharSequence name,
java.lang.CharSequence value)
null or a Java
identifier.name - the parameter name.value - the parameter value.java.lang.IllegalArgumentException - if the parameter value is neither
null nor a Java identifier.Built on April 24 2018. | Portions Copyright 1997-2018 Oracle. All rights reserved.