1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -80,8 +80,8 @@ public static void state(boolean expression, String message) {
80
80
* <p>Call {@link #isTrue} if you wish to throw an {@code IllegalArgumentException}
81
81
* on an assertion failure.
82
82
* <pre class="code">
83
- * Assert.state(id == null,
84
- * () -> "ID for " + entity.getName() + " must not already be initialized");
83
+ * Assert.state(entity.getId() == null,
84
+ * () -> "ID for entity " + entity.getName() + " must not already be initialized");
85
85
* </pre>
86
86
* @param expression a boolean expression
87
87
* @param messageSupplier a supplier for the exception message to use if the
@@ -96,6 +96,8 @@ public static void state(boolean expression, Supplier<String> messageSupplier) {
96
96
}
97
97
98
98
/**
99
+ * Assert a boolean expression, throwing an {@code IllegalStateException}
100
+ * if the expression evaluates to {@code false}.
99
101
* @deprecated as of 4.3.7, in favor of {@link #state(boolean, String)}
100
102
*/
101
103
@ Deprecated
@@ -136,6 +138,8 @@ public static void isTrue(boolean expression, Supplier<String> messageSupplier)
136
138
}
137
139
138
140
/**
141
+ * Assert a boolean expression, throwing an {@code IllegalArgumentException}
142
+ * if the expression evaluates to {@code false}.
139
143
* @deprecated as of 4.3.7, in favor of {@link #isTrue(boolean, String)}
140
144
*/
141
145
@ Deprecated
@@ -174,6 +178,7 @@ public static void isNull(@Nullable Object object, Supplier<String> messageSuppl
174
178
}
175
179
176
180
/**
181
+ * Assert that an object is {@code null}.
177
182
* @deprecated as of 4.3.7, in favor of {@link #isNull(Object, String)}
178
183
*/
179
184
@ Deprecated
@@ -197,7 +202,8 @@ public static void notNull(@Nullable Object object, String message) {
197
202
/**
198
203
* Assert that an object is not {@code null}.
199
204
* <pre class="code">
200
- * Assert.notNull(clazz, () -> "The class '" + clazz.getName() + "' must not be null");
205
+ * Assert.notNull(entity.getId(),
206
+ * () -> "ID for entity " + entity.getName() + " must not be null");
201
207
* </pre>
202
208
* @param object the object to check
203
209
* @param messageSupplier a supplier for the exception message to use if the
@@ -212,6 +218,7 @@ public static void notNull(@Nullable Object object, Supplier<String> messageSupp
212
218
}
213
219
214
220
/**
221
+ * Assert that an object is not {@code null}.
215
222
* @deprecated as of 4.3.7, in favor of {@link #notNull(Object, String)}
216
223
*/
217
224
@ Deprecated
@@ -225,8 +232,8 @@ public static void notNull(@Nullable Object object) {
225
232
* <pre class="code">Assert.hasLength(name, "Name must not be empty");</pre>
226
233
* @param text the String to check
227
234
* @param message the exception message to use if the assertion fails
228
- * @see StringUtils#hasLength
229
235
* @throws IllegalArgumentException if the text is empty
236
+ * @see StringUtils#hasLength
230
237
*/
231
238
public static void hasLength (@ Nullable String text , String message ) {
232
239
if (!StringUtils .hasLength (text )) {
@@ -238,14 +245,15 @@ public static void hasLength(@Nullable String text, String message) {
238
245
* Assert that the given String is not empty; that is,
239
246
* it must not be {@code null} and not the empty String.
240
247
* <pre class="code">
241
- * Assert.hasLength(name, () -> "Name for account '" + account.getId() + "' must not be empty");
248
+ * Assert.hasLength(account.getName(),
249
+ * () -> "Name for account '" + account.getId() + "' must not be empty");
242
250
* </pre>
243
251
* @param text the String to check
244
252
* @param messageSupplier a supplier for the exception message to use if the
245
253
* assertion fails
246
- * @see StringUtils#hasLength
247
254
* @throws IllegalArgumentException if the text is empty
248
255
* @since 5.0
256
+ * @see StringUtils#hasLength
249
257
*/
250
258
public static void hasLength (@ Nullable String text , Supplier <String > messageSupplier ) {
251
259
if (!StringUtils .hasLength (text )) {
@@ -254,6 +262,8 @@ public static void hasLength(@Nullable String text, Supplier<String> messageSupp
254
262
}
255
263
256
264
/**
265
+ * Assert that the given String is not empty; that is,
266
+ * it must not be {@code null} and not the empty String.
257
267
* @deprecated as of 4.3.7, in favor of {@link #hasLength(String, String)}
258
268
*/
259
269
@ Deprecated
@@ -268,8 +278,8 @@ public static void hasLength(@Nullable String text) {
268
278
* <pre class="code">Assert.hasText(name, "'name' must not be empty");</pre>
269
279
* @param text the String to check
270
280
* @param message the exception message to use if the assertion fails
271
- * @see StringUtils#hasText
272
281
* @throws IllegalArgumentException if the text does not contain valid text content
282
+ * @see StringUtils#hasText
273
283
*/
274
284
public static void hasText (@ Nullable String text , String message ) {
275
285
if (!StringUtils .hasText (text )) {
@@ -281,14 +291,15 @@ public static void hasText(@Nullable String text, String message) {
281
291
* Assert that the given String contains valid text content; that is, it must not
282
292
* be {@code null} and must contain at least one non-whitespace character.
283
293
* <pre class="code">
284
- * Assert.hasText(name, () -> "Name for account '" + account.getId() + "' must not be empty");
294
+ * Assert.hasText(account.getName(),
295
+ * () -> "Name for account '" + account.getId() + "' must not be empty");
285
296
* </pre>
286
297
* @param text the String to check
287
298
* @param messageSupplier a supplier for the exception message to use if the
288
299
* assertion fails
289
- * @see StringUtils#hasText
290
300
* @throws IllegalArgumentException if the text does not contain valid text content
291
301
* @since 5.0
302
+ * @see StringUtils#hasText
292
303
*/
293
304
public static void hasText (@ Nullable String text , Supplier <String > messageSupplier ) {
294
305
if (!StringUtils .hasText (text )) {
@@ -297,6 +308,8 @@ public static void hasText(@Nullable String text, Supplier<String> messageSuppli
297
308
}
298
309
299
310
/**
311
+ * Assert that the given String contains valid text content; that is, it must not
312
+ * be {@code null} and must contain at least one non-whitespace character.
300
313
* @deprecated as of 4.3.7, in favor of {@link #hasText(String, String)}
301
314
*/
302
315
@ Deprecated
@@ -340,6 +353,7 @@ public static void doesNotContain(@Nullable String textToSearch, String substrin
340
353
}
341
354
342
355
/**
356
+ * Assert that the given text does not contain the given substring.
343
357
* @deprecated as of 4.3.7, in favor of {@link #doesNotContain(String, String, String)}
344
358
*/
345
359
@ Deprecated
@@ -381,6 +395,8 @@ public static void notEmpty(@Nullable Object[] array, Supplier<String> messageSu
381
395
}
382
396
383
397
/**
398
+ * Assert that an array contains elements; that is, it must not be
399
+ * {@code null} and must contain at least one element.
384
400
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Object[], String)}
385
401
*/
386
402
@ Deprecated
@@ -429,6 +445,7 @@ public static void noNullElements(@Nullable Object[] array, Supplier<String> mes
429
445
}
430
446
431
447
/**
448
+ * Assert that an array contains no {@code null} elements.
432
449
* @deprecated as of 4.3.7, in favor of {@link #noNullElements(Object[], String)}
433
450
*/
434
451
@ Deprecated
@@ -471,6 +488,8 @@ public static void notEmpty(@Nullable Collection<?> collection, Supplier<String>
471
488
}
472
489
473
490
/**
491
+ * Assert that a collection contains elements; that is, it must not be
492
+ * {@code null} and must contain at least one element.
474
493
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Collection, String)}
475
494
*/
476
495
@ Deprecated
@@ -512,6 +531,8 @@ public static void notEmpty(@Nullable Map<?, ?> map, Supplier<String> messageSup
512
531
}
513
532
514
533
/**
534
+ * Assert that a Map contains entries; that is, it must not be {@code null}
535
+ * and must contain at least one entry.
515
536
* @deprecated as of 4.3.7, in favor of {@link #notEmpty(Map, String)}
516
537
*/
517
538
@ Deprecated
0 commit comments