1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.accumulo.core.util;
18
19 /**
20 * This class provides methods to check arguments of a variable number for null values, or anything else that might be required on a routine basis. These
21 * methods should be used for early failures as close to the end user as possible, so things do not fail later on the server side, when they are harder to
22 * debug.
23 *
24 * Methods are created for a specific number of arguments, due to the poor performance of array allocation for varargs methods.
25 */
26 public class ArgumentChecker {
27 private static final String NULL_ARG_MSG = "argument was null";
28
29 public static final void notNull(final Object arg1) {
30 if (arg1 == null)
31 throw new IllegalArgumentException(NULL_ARG_MSG + ":Is null- arg1? " + (arg1 == null));
32 }
33
34 public static final void notNull(final Object arg1, final Object arg2) {
35 if (arg1 == null || arg2 == null)
36 throw new IllegalArgumentException(NULL_ARG_MSG + ":Is null- arg1? " + (arg1 == null) + " arg2? " + (arg2 == null));
37 }
38
39 public static final void notNull(final Object arg1, final Object arg2, final Object arg3) {
40 if (arg1 == null || arg2 == null || arg3 == null)
41 throw new IllegalArgumentException(NULL_ARG_MSG + ":Is null- arg1? " + (arg1 == null) + " arg2? " + (arg2 == null) + " arg3? " + (arg3 == null));
42 }
43
44 public static final void notNull(final Object arg1, final Object arg2, final Object arg3, final Object arg4) {
45 if (arg1 == null || arg2 == null || arg3 == null || arg4 == null)
46 throw new IllegalArgumentException(NULL_ARG_MSG + ":Is null- arg1? " + (arg1 == null) + " arg2? " + (arg2 == null) + " arg3? " + (arg3 == null)
47 + " arg4? " + (arg4 == null));
48 }
49
50 public static final void notNull(final Object[] args) {
51 if (args == null)
52 throw new IllegalArgumentException(NULL_ARG_MSG + ":arg array is null");
53
54 for (int i = 0; i < args.length; i++)
55 if (args[i] == null)
56 throw new IllegalArgumentException(NULL_ARG_MSG + ":arg" + i + " is null");
57 }
58
59 public static final void strictlyPositive(final int i) {
60 if (i <= 0)
61 throw new IllegalArgumentException("integer should be > 0, was " + i);
62 }
63 }