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,
13: Object object) throws IllegalArgumentException {
14: ensureTrue(message, object != null);
15: }
16:
17: public static void ensureArgumentNotNull(Object object)
18: throws IllegalArgumentException {
19: ensureArgumentNotNull("Object must not be null", object); //$NON-NLS-1$
20: }
21:
22: public static void ensureArgumentFalse(boolean state)
23: throws IllegalArgumentException {
24: ensureTrue("boolean must be false", !state); //$NON-NLS-1$
25: }
26:
27: public static void ensureArgumentFalse(String message, boolean state)
28: throws IllegalArgumentException {
29: ensureTrue(message, !state);
30: }
31:
32: public static void ensureArgumentTrue(boolean state)
33: throws IllegalArgumentException {
34: ensureTrue("boolean must be true", state); //$NON-NLS-1$
35: }
36:
37: public static void ensureTrue(String message, boolean state)
38: throws IllegalArgumentException {
39: if (!state) {
40: throw new IllegalArgumentException(message);
41: }
42: }
43: }
|