public final class Assert extends Object
Assert
is useful for for embedding runtime sanity checks
in code. The predicate methods all test a condition and throw some
type of unchecked exception if the condition does not hold.
Assertion failure exceptions, like most runtime exceptions, are thrown when something is misbehaving. Assertion failures are invariably unspecified behavior; consequently, clients should never rely on these being thrown (and certainly should not be catching them specifically).
This class can be used without OSGi running.
This class is not intended to be instantiated or sub-classed by clients.
Modifier and Type | Method and Description |
---|---|
static boolean |
isLegal(boolean expression)
Asserts that an argument is legal.
|
static boolean |
isLegal(boolean expression,
String message)
Asserts that an argument is legal.
|
static void |
isNotNull(Object object)
Asserts that the given object is not
null . |
static void |
isNotNull(Object object,
String message)
Asserts that the given object is not
null . |
static boolean |
isTrue(boolean expression)
Asserts that the given boolean is
true . |
static boolean |
isTrue(boolean expression,
String message)
Asserts that the given boolean is
true . |
public static boolean isLegal(boolean expression)
true
, an IllegalArgumentException
is thrown.expression
- the outcome of the checktrue
if the check passes (does not return
if the check fails)IllegalArgumentException
- if the legality test failedpublic static boolean isLegal(boolean expression, String message)
true
, an IllegalArgumentException
is thrown.
The given message is included in that exception, to aid debugging.expression
- the outcome of the checkmessage
- the message to include in the exceptiontrue
if the check passes (does not return
if the check fails)IllegalArgumentException
- if the legality test failedpublic static void isNotNull(Object object)
null
. If this
is not the case, some kind of unchecked exception is thrown.object
- the value to testpublic static void isNotNull(Object object, String message)
null
. If this
is not the case, some kind of unchecked exception is thrown.
The given message is included in that exception, to aid debugging.object
- the value to testmessage
- the message to include in the exceptionpublic static boolean isTrue(boolean expression)
true
. If this
is not the case, some kind of unchecked exception is thrown.expression
- the outcome of the checktrue
if the check passes (does not return
if the check fails)public static boolean isTrue(boolean expression, String message)
true
. If this
is not the case, some kind of unchecked exception is thrown.
The given message is included in that exception, to aid debugging.expression
- the outcome of the checkmessage
- the message to include in the exceptiontrue
if the check passes (does not return
if the check fails)
Copyright (c) 2000, 2014 Eclipse Contributors and others. All rights reserved.Guidelines for using Eclipse APIs.