01 package de.java2html.util;
02
03 /**
04 * Provides convenient methods for checking contract parameters.
05 */
06 public class Ensure {
07
08 public Ensure() {
09 super();
10 }
11
12 public static void ensureArgumentNotNull(String message, Object object) throws IllegalArgumentException {
13 ensureTrue(message, object != null);
14 }
15
16 public static void ensureArgumentNotNull(Object object) throws IllegalArgumentException {
17 ensureArgumentNotNull("Object must not be null", object); //$NON-NLS-1$
18 }
19
20 public static void ensureArgumentFalse(boolean state) throws IllegalArgumentException {
21 ensureTrue("boolean must be false", !state); //$NON-NLS-1$
22 }
23
24 public static void ensureArgumentFalse(String message, boolean state) throws IllegalArgumentException {
25 ensureTrue(message, !state);
26 }
27
28 public static void ensureArgumentTrue(boolean state) throws IllegalArgumentException {
29 ensureTrue("boolean must be true", state); //$NON-NLS-1$
30 }
31
32 public static void ensureTrue(String message, boolean state) throws IllegalArgumentException {
33 if (!state){
34 throw new IllegalArgumentException(message);
35 }
36 }
37 }
|