|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.webmancer.util.ContractChecker
public class ContractChecker
This class defines a set of methods for contract checking.
Method Summary | |
---|---|
static void |
checkState(boolean legalState,
java.lang.String errorMessage)
Throw the IllegalStateException with the given errorMessage if the legalState
is false . |
static void |
mustBe(boolean condition,
java.lang.String message)
Throws the IllegalArgumentException if the given condition is false . |
static void |
mustBeGreater(double parameter,
double ref,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is lower or equal to the given
reference value ref . |
static void |
mustBeGreaterEq(double parameter,
double ref,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is lower than the given
reference value ref . |
static void |
mustBeInRange(double parameter,
double lowerBound,
double upperBound,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is not in the range specified
by the lowerBound and upperBound values. |
static void |
mustBeInstanceOf(java.lang.Object parameter,
java.lang.Class[] classes,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is not an instance of either
class in classes . |
static void |
mustBeInstanceOf(java.lang.Object parameter,
java.lang.Class clazz,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is not an instance of class clazz . |
static void |
mustBeLess(double parameter,
double ref,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is greater or equal to the
given reference value ref . |
static void |
mustBeLessEq(double parameter,
double ref,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is greater than the given
reference value ref . |
static void |
mustBeNegative(double parameter,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is greater or equal to zero. |
static void |
mustBePositive(double parameter,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is lower or equal to zero. |
static void |
mustNotBeEmpty(java.lang.Object[] parameter,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is null or an
array of size 0. |
static void |
mustNotBeEmpty(java.lang.String parameter,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is null or empty
string (after trim). |
static void |
mustNotBeNegative(double parameter,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is lower than zero. |
static void |
mustNotBeNull(java.lang.Object parameter,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is null . |
static void |
mustNotBePositive(double parameter,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is greater than zero. |
static void |
mustNotBeZero(double parameter,
java.lang.String name)
Throws the IllegalArgumentException if the given parameter is equal to zero |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static void checkState(boolean legalState, java.lang.String errorMessage) throws java.lang.IllegalStateException
IllegalStateException
with the given errorMessage
if the legalState
is false
.
legalState
- The state to be checkederrorMessage
- The error message
java.lang.IllegalStateException
- Thrown if the legalState
is false
public static void mustBe(boolean condition, java.lang.String message) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given condition
is false
.
condition
- The condition that must be true
or the exception is thrownmessage
- The error message
java.lang.IllegalArgumentException
- Thrown if the condition
is false
public static void mustBeInstanceOf(java.lang.Object parameter, java.lang.Class clazz, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is not an instance of class clazz
.
parameter
- The parameter being checkedclazz
- The reference classname
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustBeInstanceOf(java.lang.Object parameter, java.lang.Class[] classes, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is not an instance of either
class in classes
.
parameter
- The parameter being checkedclasses
- The array of classesname
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustNotBeNull(java.lang.Object parameter, java.lang.String name) throws java.lang.NullPointerException
IllegalArgumentException
if the given parameter
is null
.
parameter
- The parameter that has to be non-null
name
- The name of the parameter being checked
java.lang.NullPointerException
- Thrown if the checked condition is not satisfiedpublic static void mustNotBeEmpty(java.lang.String parameter, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is null
or empty
string (after trim).
parameter
- The parameter that has to be non-null
and non-empty stringname
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustNotBeEmpty(java.lang.Object[] parameter, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is null
or an
array of size 0.
parameter
- The parameter that has to be non-null
and non-zero-length arrayname
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustBeNegative(double parameter, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is greater or equal to zero.
parameter
- The parameter that has to be negativename
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustBePositive(double parameter, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is lower or equal to zero.
parameter
- The parameter that has to be positivename
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustNotBeNegative(double parameter, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is lower than zero.
parameter
- The parameter that has to be positive or zeroname
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustNotBePositive(double parameter, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is greater than zero.
parameter
- The parameter that has to be negative or zeroname
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustNotBeZero(double parameter, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is equal to zero
parameter
- The parameter that has to be non-zeroname
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustBeGreater(double parameter, double ref, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is lower or equal to the given
reference value ref
.
parameter
- The parameter that has to be greater than given reference value ref
ref
- The reference value the parameter is compared toname
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustBeGreaterEq(double parameter, double ref, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is lower than the given
reference value ref
.
parameter
- The parameter that has to be greater or equal to the given reference value ref
ref
- The reference value the parameter is compared toname
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustBeLess(double parameter, double ref, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is greater or equal to the
given reference value ref
.
parameter
- The parameter that has to be lower than given reference value ref
ref
- The reference value the parameter is compared toname
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustBeLessEq(double parameter, double ref, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is greater than the given
reference value ref
.
parameter
- The parameter that has to be lower or equal to the given reference value ref
ref
- The reference value the parameter is compared toname
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfiedpublic static void mustBeInRange(double parameter, double lowerBound, double upperBound, java.lang.String name) throws java.lang.IllegalArgumentException
IllegalArgumentException
if the given parameter
is not in the range specified
by the lowerBound
and upperBound
values.
parameter
- The parameter that has to be in the range specified by the lowerBound
and
upperBound
values.lowerBound
- The lower bound of the interval the parameter is compared toupperBound
- The upper bound of the interval the parameter is compared toname
- The name of the parameter being checked
java.lang.IllegalArgumentException
- Thrown if the checked condition is not satisfied
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |