public final class Precondition extends Object
NullPointerException
is not provided because this
exception is thrown when an application attempts to use null
in a
case where an object is required, so it should not be thrown when
null
is an illegal argument or an illegal state.Modifier and Type | Method and Description |
---|---|
static void |
argument(boolean precondition,
String errorMessage)
Enforces a precondition on an argument.
|
static void |
element(boolean precondition,
String errorMessage)
Enforces a precondition on non-emptiness for collections or iterators.
|
static void |
index(boolean precondition,
String errorMessage)
Enforces a precondition on an index for random access data structures.
|
static void |
state(boolean precondition,
String errorMessage)
Enforces a precondition on the state.
|
public static void argument(boolean precondition, String errorMessage)
IllegalArgumentException
is thrown with the provided error message.precondition
- the precondition to be enforcederrorMessage
- the description of the violated preconditionpublic static void state(boolean precondition, String errorMessage)
IllegalStateException
is thrown with the provided error message.precondition
- the precondition to be enforcederrorMessage
- the description of the violated preconditionpublic static void index(boolean precondition, String errorMessage)
IndexOutOfBoundsException
is thrown with the provided error message.
argument(boolean, String)
instead of this method.precondition
- the precondition to be enforcederrorMessage
- the description of the violated preconditionpublic static void element(boolean precondition, String errorMessage)
NoSuchElementException
is thrown with the provided error message.
state(boolean, String)
instead of this method. However there exist interface methods whose
contract states that they throw NoSuchElementException
, like
Iterator.next()
: implementations must
observe such contracts.precondition
- the precondition to be enforcederrorMessage
- the description of the violated preconditionCopyright © 2013. All Rights Reserved.