KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > java2html > util > Ensure


1 package de.java2html.util;
2
3 /**
4  * Provides convenient methods for checking contract parameters.
5  */

6 public class Ensure {
7
8   public Ensure() {
9     super();
10   }
11
12   public static void ensureArgumentNotNull(String JavaDoc message, Object JavaDoc object) throws IllegalArgumentException JavaDoc {
13     ensureTrue(message, object != null);
14   }
15
16   public static void ensureArgumentNotNull(Object JavaDoc object) throws IllegalArgumentException JavaDoc {
17     ensureArgumentNotNull("Object must not be null", object); //$NON-NLS-1$
18
}
19
20   public static void ensureArgumentFalse(boolean state) throws IllegalArgumentException JavaDoc {
21     ensureTrue("boolean must be false", !state); //$NON-NLS-1$
22
}
23
24   public static void ensureArgumentFalse(String JavaDoc message, boolean state) throws IllegalArgumentException JavaDoc {
25     ensureTrue(message, !state);
26   }
27
28   public static void ensureArgumentTrue(boolean state) throws IllegalArgumentException JavaDoc {
29     ensureTrue("boolean must be true", state); //$NON-NLS-1$
30
}
31
32   public static void ensureTrue(String JavaDoc message, boolean state) throws IllegalArgumentException JavaDoc {
33     if (!state){
34       throw new IllegalArgumentException JavaDoc(message);
35     }
36   }
37 }
Popular Tags