public final class Validate extends Object
| Modifier | Constructor and Description |
|---|---|
private |
Validate()
Hidden for pure static class.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
greaterThan(int reference,
int lowerBound)
Convenience method for
greaterThan(int, int, java.lang.String) with null as name. |
static int |
greaterThan(int reference,
int lowerBound,
String name)
Tests that a given integer reference value is greater than the given lower bound.
|
static long |
greaterThan(long reference,
long lowerBound)
Convenience method for
greaterThan(long, long, java.lang.String) with null as name. |
static long |
greaterThan(long reference,
long lowerBound,
String name)
Tests that a given integer reference value is greater than the given lower bound.
|
static int |
greaterThanOrEqual(int reference,
int lowerBound)
Convenience method for
greaterThanOrEqual(int, int, java.lang.String) with null as name. |
static int |
greaterThanOrEqual(int reference,
int lowerBound,
String name)
Tests that a given integer reference value is greater than or equal the given lower bound.
|
static long |
greaterThanOrEqual(long reference,
long lowerBound)
Convenience method for
greaterThanOrEqual(long, long, java.lang.String) with null as name. |
static long |
greaterThanOrEqual(long reference,
long lowerBound,
String name)
Tests that a given integer reference value is greater than or equal the given lower bound.
|
static void |
isTrue(boolean expression,
String message)
Tests that a given expression is true.
|
static String |
notEmpty(String reference)
Convenience message for
notEmpty(java.lang.String, java.lang.String) with null as second
parameter. |
static String |
notEmpty(String reference,
String name)
Validates that a given string reference is not
null or empty. |
static <T> T |
notNull(T reference)
Convenience message for
notNull(java.lang.Object, java.lang.String) with null as second
parameter. |
static <T> T |
notNull(T reference,
String name)
Validates that a given reference is not
null. |
public static <T> T notNull(T reference,
String name)
null.
This example validates that input is not null. If it is null a NullPointerException will
be thrown with the name as hint in the exception message.:
void someMethod(final Object input) {
final Object validInput = Validate.notNull(input, "input");
// ...
}
The second parameter name may be omitted. Then a NullPointerException without any message will be
thrown. For this purpose you can call the convenience method notNull(java.lang.Object).
T - type of referencereference - validated referencename - name of validated reference, may be nullpublic static <T> T notNull(T reference)
notNull(java.lang.Object, java.lang.String) with null as second
parameter.T - type of referencereference - validated referencepublic static String notEmpty(String reference, String name)
null or empty.
This example validates that input is not null. If it is null a NullPointerException will
be thrown with the name as hint in the exception message. Also it validates that input is not
empty by calling String.isEmpty(). If the string is empty an IllegalArgumentException will be
thrown:
void someMethod(final String input) {
final Strign validInput = Validate.notEmpty(input, "input");
// ...
}
The second parameter name may be omitted. Then a NullPointerException or
IllegalArgumentException without any message will be thrown. For this purpose you can call the
convenience method notEmpty(java.lang.String).
reference - validated referencename - name of validated reference, may be nullpublic static String notEmpty(String reference)
notEmpty(java.lang.String, java.lang.String) with null as second
parameter.reference - validated referencepublic static int greaterThan(int reference,
int lowerBound,
String name)
The method throws an IllegalArgumentException if the given reference is less than or equal the given
lower bound value.
reference - validated referencelowerBound - bound to test againstname - name of validated reference, may be nullpublic static int greaterThan(int reference,
int lowerBound)
greaterThan(int, int, java.lang.String) with null as name.reference - validated referencelowerBound - bound to test againstpublic static int greaterThanOrEqual(int reference,
int lowerBound,
String name)
The method throws an IllegalArgumentException if the given reference is less than the given
lower bound value.
reference - validated referencelowerBound - bound to test againstname - name of validated reference, may be nullpublic static int greaterThanOrEqual(int reference,
int lowerBound)
greaterThanOrEqual(int, int, java.lang.String) with null as name.reference - validated referencelowerBound - bound to test againstpublic static long greaterThan(long reference,
long lowerBound,
String name)
The method throws an IllegalArgumentException if the given reference is less than or equal the given
lower bound value.
reference - validated referencelowerBound - bound to test againstname - name of validated reference, may be nullpublic static long greaterThan(long reference,
long lowerBound)
greaterThan(long, long, java.lang.String) with null as name.reference - validated referencelowerBound - bound to test againstpublic static long greaterThanOrEqual(long reference,
long lowerBound,
String name)
The method throws an IllegalArgumentException if the given reference is less than the given
lower bound value.
reference - validated referencelowerBound - bound to test againstname - name of validated reference, may be nullpublic static long greaterThanOrEqual(long reference,
long lowerBound)
greaterThanOrEqual(long, long, java.lang.String) with null as name.reference - validated referencelowerBound - bound to test againstpublic static void isTrue(boolean expression,
String message)
Throws an IllegalArgumentException if the expression is false.
expression - tested expressionmessage - must not be null or emptyCopyright © 2014 Sven Strittmatter. All Rights Reserved.