KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > dependencies > Assert


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.core.internal.dependencies;
13
14 /**
15  * <code>Assert</code> is useful for for embedding runtime sanity checks
16  * in code.
17  * The predicate methods all test a condition and throw some
18  * type of unchecked exception if the condition does not hold.
19  * <p>
20  * Assertion failure exceptions, like most runtime exceptions, are
21  * thrown when something is misbehaving. Assertion failures are invariably
22  * unspecified behavior; consequently, clients should never rely on
23  * these being thrown (and certainly should not being catching them
24  * specifically).
25  * </p>
26  */

27 public final class Assert {
28     private Assert() {
29         // This class is not intended to be instantiated
30
}
31
32     /** Asserts that the given object is not <code>null</code>. If this
33      * is not the case, some kind of unchecked exception is thrown.
34      *
35      * @param object the value to test
36      * @exception IllegalArgumentException if the object is <code>null</code>
37      */

38     public static void isNotNull(Object JavaDoc object) {
39         isNotNull(object, ""); //$NON-NLS-1$
40
}
41
42     /** Asserts that the given object is not <code>null</code>. If this
43      * is not the case, some kind of unchecked exception is thrown.
44      * The given message is included in that exception, to aid debugging.
45      *
46      * @param object the value to test
47      * @param message the message to include in the exception
48      * @exception IllegalArgumentException if the object is <code>null</code>
49      */

50     public static void isNotNull(Object JavaDoc object, String JavaDoc message) {
51         if (object == null)
52             throw new NullPointerException JavaDoc("null argument:" + message); //$NON-NLS-1$
53
}
54 }
Popular Tags