KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > util > Assert


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.admin.util;
25 /**
26     Use Assert to checkpoint conditions within the code.
27  */

28 public class Assert
29 {
30     /*
31         An assertion has failed, do something with the message.
32      */

33         static private final void
34     throwIt( String JavaDoc msg )
35     {
36         AssertError e = new AssertError( msg );
37         // always print it here, so it will be seen
38
e.printStackTrace();
39         throw e;
40     }
41     
42     /**
43         If expression is false, throw an AssertError which
44         incorporates the message.
45         <p>
46         If expression is true, do nothing.
47         
48         @param assertIsTrue boolean derived from callers expression.
49         @param msg message to be added to AssertError upon failure
50      */

51         static public final void
52     assertit( boolean assertIsTrue, Object JavaDoc msg )
53     {
54         if ( ! assertIsTrue )
55         {
56             throwIt( msg.toString() );
57         }
58     }
59     
60         static public final void
61     assertRange( int value, int min, int max, Object JavaDoc msgIn )
62     {
63         assertRange( (long)value, (long)min, (long)max, msgIn );
64     }
65     
66     
67         static public final void
68     assertRange( long value, long min, long max, Object JavaDoc msgIn )
69     {
70         if ( value < min || value > max )
71         {
72             String JavaDoc rangeString = "[" + min + ", " + max + "]";
73             String JavaDoc msg = "illegal integer value = " + value +
74                 " must be in range " + rangeString;
75                 
76             if ( msgIn != null )
77             {
78                 msg += " ( " + msgIn + " )";
79             }
80             
81             throwIt( msg );
82         }
83     }
84 };
85
86
87
Popular Tags