public abstract class Assert extends Object
IllegalArgumentException
exception only.
For a message format see the MsgFormatter#format(java.lang.Object...)
method description.
Assert.isTrue(true, "TEST:{}{}", "A", "B"); Assert.isTrue(30, (x) -> x > 20, "Wrong No"); Assert.notNull("ABC"); Assert.hasLength("ABC"); Assert.hasLength(new char[]{'A','B','C'}); Assert.hasLength(new StringBuilder().append("ABC")); Assert.hasLength(Arrays.asList("A", "B", "C")); Assert.isFalse(false); Assert.isFalse(15, (x) -> x > 20); Assert.isNull (null); Assert.isEmpty(""); Assert.isEmpty(new char[0]); Assert.isEmpty(new StringBuilder()); Assert.isEmpty((List) null);
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/Assert.html
,
https://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/Validate.html
,
https://google.github.io/guava/releases/19.0/api/docs/com/google/common/base/Preconditions.html
Modifier and Type | Field and Description |
---|---|
static Object[] |
NO_MESSAGE
No messge constant
|
Modifier and Type | Method and Description |
---|---|
static void |
hasLength(byte[] array,
Object... message)
Checks if the argument is not empty, nor
null . |
static void |
hasLength(Collection<?> values,
Object... message)
Checks if the argument is not empty, nor
null . |
static void |
hasLength(char[] array,
Object... message)
Checks if the argument is not empty, nor
null . |
static void |
hasLength(CharSequence value,
Object... message)
Checks if the argument is not empty, nor
null . |
static void |
hasLength(Map<?,?> values,
Object... message)
Checks if the argument is not empty, nor
null . |
static void |
hasLength(Object[] values,
Object... message)
Checks if the argument is not empty, nor
null . |
static void |
isEmpty(byte[] array,
Object... message)
Checks if the argument is not empty, nor
null . |
static void |
isEmpty(Collection<?> values,
Object... message)
Checks if the argument is not empty, nor
null . |
static void |
isEmpty(char[] array,
Object... message)
Checks if the argument is not empty, nor
null . |
static void |
isEmpty(CharSequence value,
Object... message)
Checks if the argument is not empty, nor
null . |
static void |
isEmpty(Map<?,?> values,
Object... message)
Checks if the argument is not empty, nor
null . |
static void |
isEmpty(Object[] values,
Object... message)
Checks if the argument is not empty, nor
null . |
static void |
isFalse(boolean condition)
Checks if the argument is
false . |
static void |
isFalse(boolean condition,
Object... message)
Checks if the argument is
false . |
static <T> void |
isFalse(T value,
Predicate<T> predicate,
Object... message)
|
static <T> void |
isFalseNullable(T value,
Predicate<T> predicate,
Object... message)
Checks if the argument of the the method
Predicate.test() is
false . |
static void |
isNull(Object value)
Checks if the argument is
null . |
static void |
isNull(Object value,
Object... message)
Checks if the argument is
null . |
static void |
isTrue(boolean condition)
Checks if the argument is
true . |
static void |
isTrue(boolean condition,
Object... message)
Checks if the argument is
true . |
static <T> void |
isTrue(T condition,
Predicate<T> predicate,
Object... message)
|
static <T> void |
isTrueNullable(T value,
Predicate<T> predicate,
Object... message)
Checks if the value is result of the the method
Predicate.test() is
true . |
static void |
notNull(Object value)
Checks if the argument is not
null . |
static void |
notNull(Object value,
Object... message)
Checks if the argument is not
null . |
static void |
validState(boolean condition,
Object... message)
If the value Checks if the argument is
true . |
public static final Object[] NO_MESSAGE
public static final void validState(boolean condition, @Nullable Object... message) throws IllegalStateException
true
.IllegalStateException
- When the condtion is falsepublic static final void isTrue(boolean condition) throws IllegalArgumentException
true
.IllegalArgumentException
public static final void isTrue(boolean condition, @Nullable Object... message) throws IllegalArgumentException
true
.IllegalArgumentException
public static <T> void isTrue(@Nullable T condition, @Nonnull Predicate<T> predicate, @Nullable Object... message)
public static <T> void isTrueNullable(@Nullable T value, @Nonnull Predicate<T> predicate, @Nullable Object... message)
true
.
An argument of the Predicable#test()
method can be null
.public static final void notNull(@Nullable Object value) throws IllegalArgumentException
null
.IllegalArgumentException
public static void notNull(@Nullable Object value, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void hasLength(@Nullable byte[] array, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void hasLength(@Nullable char[] array, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void hasLength(@Nullable Object[] values, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void hasLength(@Nullable Collection<?> values, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void hasLength(@Nullable Map<?,?> values, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void hasLength(@Nullable CharSequence value, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static final void isFalse(boolean condition) throws IllegalArgumentException
false
.IllegalArgumentException
public static final void isFalse(boolean condition, @Nullable Object... message) throws IllegalArgumentException
false
.IllegalArgumentException
public static <T> void isFalse(@Nullable T value, @Nonnull Predicate<T> predicate, @Nullable Object... message)
public static <T> void isFalseNullable(@Nullable T value, @Nonnull Predicate<T> predicate, @Nullable Object... message)
false
.
An argument of the Predicable#test()
method can be null
.public static final void isNull(@Nullable Object value) throws IllegalArgumentException
null
.IllegalArgumentException
public static void isNull(@Nullable Object value, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void isEmpty(byte[] array, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void isEmpty(@Nullable char[] array, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void isEmpty(@Nullable Object[] values, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void isEmpty(@Nullable Collection<?> values, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void isEmpty(@Nullable Map<?,?> values, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void isEmpty(@Nullable CharSequence value, @Nullable Object... message) throws IllegalArgumentException
null
.IllegalArgumentException
Copyright 2019-2022, Pavel Ponec