1 package com.zmicer.utils;
2
3 import org.apache.log4j.Logger;
4
5
6
7
8
9
10
11
12 public class InputArgumentUtils
13 {
14
15
16
17 final public static Logger LOG = Logger.getLogger(InputArgumentUtils.class);
18
19
20
21
22
23
24
25
26
27
28 public static void checkObjects(final Object... objects)
29 {
30 if (null == objects)
31 {
32 throw new IllegalArgumentException("The var arg list of input arguments to be checked, can not be null.");
33 }
34 boolean someOfParamsNull = false;
35
36 boolean[] info = new boolean[objects.length];
37
38 int counter = 0;
39 for (Object object : objects)
40 {
41 if (null == object)
42 {
43 info[counter] = true;
44 someOfParamsNull = true;
45 }
46 counter++;
47 }
48 if (someOfParamsNull)
49 {
50 String toOutStr = "";
51 for (int i = 0; i < info.length; i++)
52 {
53 if (info[i])
54 {
55 toOutStr += " " + i;
56 }
57 }
58 throw new IllegalArgumentException("All the params passed to the checkObjects method can not be null - " + toOutStr +
59 " are null");
60 }
61 }
62
63
64
65
66
67
68
69
70 public static void checkStrings(final boolean checkOnEmpty, final String... strings)
71 {
72 checkObjects((Object[])strings);
73 if (checkOnEmpty)
74 {
75 for (final String str : strings)
76 {
77 if ("".equals(str.trim()))
78 {
79 throw new IllegalArgumentException("The provided var args should contains not null and not empty String objects");
80 }
81 }
82 }
83 }
84 }