1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util;
17
18 import java.io.File;
19
20 import org.apache.commons.lang3.StringUtils;
21
22 public abstract class Assert extends org.springframework.util.Assert {
23
24 private static final String NO_NULLS = "null not allowed";
25 private static final String NO_BLANKS = "blank strings not allowed";
26
27 public static void exists(String location) {
28 exists(location, "[" + location + "] does not exist");
29 }
30
31 public static void exists(String location, String message) {
32 isTrue(LocationUtils.exists(location), message);
33 }
34
35 public static void isExistingDir(File dir) {
36 isExistingDir(dir, "[" + dir + "] is not an existing directory");
37 }
38
39 public static void isExistingDir(File dir, String message) {
40 exists(dir, message);
41 isTrue(dir.isDirectory(), message);
42 }
43
44 public static void exists(File file) {
45 exists(file, "[" + file + "] does not exist");
46 }
47
48 public static void exists(File file, String message) {
49 isTrue(file.exists(), message);
50 }
51
52 public static void isOdd(int i) {
53 isOdd(i, "[" + i + "] is not an odd number");
54 }
55
56 public static void isOdd(int i, String message) {
57 isTrue(i % 2 != 0, message);
58 }
59
60 public static void isEven(int i) {
61 isEven(i, "[" + i + "] is not an even number");
62 }
63
64 public static void isEven(int i, String message) {
65 isTrue(i % 2 == 0, message);
66 }
67
68 public static void isFalse(boolean condition) {
69 isTrue(!condition);
70 }
71
72 public static void isFalse(boolean condition, String message) {
73 isTrue(!condition, message);
74 }
75
76 public static void notBlank(String string) {
77 isFalse(StringUtils.isBlank(string));
78 }
79
80 public static void noBlanks(String... strings) {
81 noBlanksWithMsg(NO_BLANKS, strings);
82 }
83
84 public static void noNullStrings(String... strings) {
85 notNull((Object) strings);
86 for (String string : strings) {
87 notNull(string, NO_NULLS);
88 }
89 }
90
91 public static void noNulls(Object... objects) {
92 noNullsWithMsg(NO_NULLS, objects);
93 }
94
95 public static void noNullsWithMsg(String msg, Object... objects) {
96 for (Object object : objects) {
97 notNull(object, msg);
98 }
99 }
100
101 public static void noBlanksWithMsg(String msg, String... strings) {
102 for (String string : strings) {
103 isFalse(StringUtils.isBlank(string), msg);
104 }
105 }
106
107 @Deprecated
108 public static void notNull(Object... objects) {
109 for (Object object : objects) {
110 notNull(object);
111 }
112 }
113
114 @Deprecated
115 public static void notBlank(String... strings) {
116 noBlanksWithMsg(NO_BLANKS, strings);
117 }
118
119 @Deprecated
120 public static void noNulls(String msg, Object... objects) {
121 for (Object object : objects) {
122 notNull(object, msg);
123 }
124 }
125
126 }