|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.jgoodies.common.base.Preconditions
public final class Preconditions
Reduces the code necessary to check preconditions on method state an parameters.
| Method Summary | ||
|---|---|---|
static void |
checkArgument(boolean expression,
String message)
Checks the truth of the given expression and throws a customize IllegalArgumentException if it is false. |
|
static void |
checkArgument(boolean expression,
String messageFormat,
Object... messageArgs)
Checks the truth of the given expression and throws a customize IllegalArgumentException if it is false. |
|
static String |
checkNotBlank(String str,
String message)
Checks that the given string is not blank and throws a customize NullPointerException if it is null, and a customize
IllegalArgumentException if it is empty or whitespace. |
|
static String |
checkNotBlank(String str,
String messageFormat,
Object... messageArgs)
Checks that the given string is not blank and throws a customize NullPointerException if it is null, and a customize
IllegalArgumentException if it is empty or whitespace. |
|
static
|
checkNotNull(T reference,
String message)
Checks that the given object reference is not nullNullPointerException if it is. |
|
static
|
checkNotNull(T reference,
String messageFormat,
Object... messageArgs)
Checks that the given object reference is not nullNullPointerException if it is. |
|
static void |
checkState(boolean expression,
String message)
Checks the truth of the given expression and throws a customize IllegalStateException if it is false. |
|
static void |
checkState(boolean expression,
String messageFormat,
Object... messageArgs)
Checks the truth of the given expression and throws a customize IllegalStateException if it is false. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static void checkArgument(boolean expression,
String message)
IllegalArgumentException if it is false. Intended for doin
parameter validation in methods and constructors, e.g.
0, "count must be positive.")
expression - the precondition to check involving one ore mor
parameters to the calling method or constructormessage - the detail message to be used in the event tha
an exception is thrown
IllegalArgumentException - if expression is false
public static void checkArgument(boolean expression,
String messageFormat,
Object... messageArgs)
IllegalArgumentException if it is false. Intended for doin
parameter validation in methods and constructors, e.g.
0, "count must be positive: %s.", count)
expression - the precondition to check involving one ore mor
parameters to the calling method or constructormessageFormat - a format string for the detail message to be use
in the event that an exception is thrown.messageArgs - the arguments referenced by the format specifier
in the messageFormat
IllegalArgumentException - if expression is false
public static <T> T checkNotNull(T reference,
String message)
nullNullPointerException if it is
Intended for doing parameter validation in methods and constructors
e.g.
T - the type of the referencereference - the object reference to check for being nullmessage - the detail message to be used in the event tha
an exception is thrown
reference if not null
NullPointerException - if reference is null
public static <T> T checkNotNull(T reference,
String messageFormat,
Object... messageArgs)
nullNullPointerException if it is
Intended for doing parameter validation in methods and constructors
e.g.
T - the type of the referencereference - the object reference to check for being nullmessageFormat - a format string for the detail message to be use
in the event that an exception is thrown.messageArgs - the arguments referenced by the format specifier
in the messageFormat
reference if not null
NullPointerException - if reference is null
public static void checkState(boolean expression,
String message)
IllegalStateException if it is false. Intended for doin
validation in methods involving the state of the calling instance
but not involving parameters of the calling method, e.g.
expression - the precondition to check involving the stat
of the calling instancemessage - the detail message to be used in the event tha
an exception is thrown
IllegalStateException - if expression is false
public static void checkState(boolean expression,
String messageFormat,
Object... messageArgs)
IllegalStateException if it is false. Intended for doin
validation in methods involving the state of the calling instance
but not involving parameters of the calling method, e.g.
expression - the precondition to check involving the stat
of the calling instancemessageFormat - a format string for the detail message to be use
in the event that an exception is thrown.messageArgs - the arguments referenced by the format specifier
in the messageFormat
IllegalStateException - if expression is false
public static String checkNotBlank(String str,
String message)
NullPointerException if it is null, and a customize
IllegalArgumentException if it is empty or whitespace
Intended for doing parameter validation in methods and constructors
e.g.
str - the string to check for being blankmessage - the detail message to be used in the event tha
an exception is thrown
str if not null
NullPointerException - if str is null
IllegalArgumentException - if str is empty or whitespace
public static String checkNotBlank(String str,
String messageFormat,
Object... messageArgs)
NullPointerException if it is null, and a customize
IllegalArgumentException if it is empty or whitespace
Intended for doing parameter validation in methods and constructors
e.g.
str - the string to check for being blankmessageFormat - a format string for the detail message to be use
in the event that an exception is thrown.messageArgs - the arguments referenced by the format specifier
in the messageFormat
str if not null
NullPointerException - if str is null
IllegalArgumentException - if str is empty or whitespace
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||