|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.mycore.common.MCRArgumentChecker
public abstract class MCRArgumentChecker
This class provides some static utility methods for checking values of arguments and conditions. This can be used to ensure that a method is not invoked with null arguments, for example. Here is a sample usage, where an MCRUsageException is thrown when "name" is empty:
public void sayHelloTo(String name) {
MCRArgumentChecker.ensureNotEmpty(name, "name");
System.out.println("Hello " + name);
}
| Constructor Summary | |
|---|---|
MCRArgumentChecker()
Deprecated. |
|
| Method Summary | |
|---|---|
static void |
ensureIsFalse(boolean expression,
String message)
Deprecated. Ensures that a given boolean expression is false, or throws an MCRUsageException with the error message provided otherwise. |
static void |
ensureIsTrue(boolean expression,
String message)
Deprecated. Ensures that a given boolean expression is true, or throws an MCRUsageException with the error message provided otherwise. |
static void |
ensureNotEmpty(String s,
String argumentName)
Deprecated. Ensures that a given String variable does not contain a null reference, or a String of length 0, or a String containing only blanks. |
static void |
ensureNotNegative(double value,
String argumentName)
Deprecated. Ensures that a given numeric value is not negative. |
static void |
ensureNotNull(Object o,
String argumentName)
Deprecated. Ensures that a given variable does not contain a null reference, or throws an MCRUsageException with an error message otherwise. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public MCRArgumentChecker()
| Method Detail |
|---|
public static void ensureIsTrue(boolean expression,
String message)
expression - the boolean expression that should be truemessage - the error message to be thrown when the expression is not true
MCRUsageException - if the expression is not true
public static void ensureIsFalse(boolean expression,
String message)
expression - the boolean expression that should be falsemessage - the error message to be thrown when the expression is true
MCRUsageException - if the expression is true
public static void ensureNotNull(Object o,
String argumentName)
o - the Object variable that must not contain a null referenceargumentName - the name of the argument variable that must not be null
MCRUsageException - if o is null
public static void ensureNotEmpty(String s,
String argumentName)
s - the String variable that must not be null of emptyargumentName - the name of the String argument
MCRUsageException - if s is null or s.trim().length() is 0
public static void ensureNotNegative(double value,
String argumentName)
value - the value that must not be negativeargumentName - the name of the number argument
MCRUsageException - if value is negative
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||