KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nl > hippo > asserts > ObjectAsserts


1 /*
2  * Copyright 2004 Hippo Webworks.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16 package nl.hippo.asserts;
17
18 public class ObjectAsserts extends Asserts
19 {
20     
21     public static void notNull(Object JavaDoc object, ExceptionFactory exceptionFactory, String JavaDoc identifier)
22     {
23         if (object == null)
24         {
25             throw createException(exceptionFactory, identifier + " cannot be null");
26         }
27     }
28     
29     public static void equal(Object JavaDoc first, Object JavaDoc second, ExceptionFactory exceptionFactory, String JavaDoc firstIdentifier, String JavaDoc secondIdentifier)
30     {
31         boolean result;
32         if (first == null)
33         {
34             result = second == null;
35         }
36         else
37         {
38             result = first.equals(second);
39         }
40         if (!result)
41         {
42             throw createException(exceptionFactory, firstIdentifier + " must be equal to " + secondIdentifier);
43         }
44     }
45
46     /**
47      * @deprecated Use the overloaded method using an exception factory instead.
48      * @param object
49      * @param exception
50      */

51     public static void notNull(Object JavaDoc object, RuntimeException JavaDoc exception)
52     {
53         if (object == null)
54         {
55             throw exception;
56         }
57     }
58     
59     private ObjectAsserts()
60     {
61         super();
62     }
63
64 }
Popular Tags