KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > util > Assertion


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) 2003-2005 QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package org.quickserver.util;
16
17 /**
18  * Class to encapsulate Assertion and allows any back ports.
19  * @since 1.4.6
20  */

21 public final class Assertion {
22     private static boolean enabled = false;
23
24     static {
25         assert enabled = true;
26     }
27
28     public static boolean isEnabled() {
29         return enabled;
30     }
31
32     public static void affirm(boolean test) {
33         assert test;
34         //assertBackport(test);
35
}
36
37     public static void affirm(boolean test, String JavaDoc msg) {
38         assert test : msg;
39         //assertBackport(test, msg);
40
}
41     
42     // Back Port versions
43
// Make sure a AssertionError class is defined that extends from Error
44
/*
45     private static void assertBackport(boolean test, String msg) {
46         if(enabled && test==false) throw new AssertionError(msg);
47         //if(enabled && test==false) throw new RuntimeException("Assertion failed: "+msg);
48     }
49
50     private static void assertBackport(boolean test) {
51         if(enabled && test==false) throw new AssertionError();
52         //if(enabled && test==false) throw new RuntimeException("Assertion failed!");
53     }
54     */

55 }
56
Popular Tags