public abstract class Assert extends Object
IllegalArgumentException
exception only.
For a message format see the MsgFormatter#format(T)
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); Assert.isTrue(true, m -> m.format ("TEST:{}{}", "A", "B")); Assert.isTrue(true, m -> m.sformat("TEST:%s%s", "A", "B"));
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 | Method and Description |
---|---|
static <M> byte[] |
hasLength(byte[] array,
M... message)
Checks if the argument is not empty, nor
null . |
static <V,M> Collection<V> |
hasLength(Collection<V> value,
M... message)
Checks if the argument is not empty, nor
null . |
static <M> char[] |
hasLength(char[] array,
M... message)
Checks if the argument is not empty, nor
null . |
static <V,K,M> Map<K,V> |
hasLength(Map<K,V> value,
M... message)
Checks if the argument is not empty, nor
null . |
static <V,M> V[] |
hasLength(V[] array,
M... message)
Checks if the argument is not empty, nor
null . |
static <V extends CharSequence,M> |
hasLength(V value,
M... message)
Checks if the argument is not empty, nor
null . |
static <M> void |
isEmpty(byte[] array,
M... message)
Checks if the argument is not empty, nor
null . |
static <M> void |
isEmpty(Collection<?> values,
M... message)
Checks if the argument is not empty, nor
null . |
static <M> void |
isEmpty(char[] array,
M... message)
Checks if the argument is not empty, nor
null . |
static <M> void |
isEmpty(CharSequence value,
M... message)
Checks if the argument is not empty, nor
null . |
static <M> void |
isEmpty(Map<?,?> values,
M... message)
Checks if the argument is not empty, nor
null . |
static <V,M> void |
isEmpty(V[] values,
M... message)
Checks if the argument is not empty, nor
null . |
static void |
isFalse(boolean condition,
Object... message)
Checks if the argument is
false . |
static <V,M> void |
isFalse(V value,
Predicate<V> predicate,
M... message)
Checks if the predicate is invalid
Predicate.test() is
false . |
static <V,M> void |
isFalseRequired(V value,
Predicate<V> predicate,
M... message)
|
static <M> void |
isNull(Object value,
M... message)
Checks if the argument is
null . |
static <V,M> Optional<V> |
isPresented(V value,
M... message)
Return a result with presented value or throw an exception.
|
static <M> void |
isTrue(boolean condition,
M... message)
Checks if the argument is
true . |
static <V,M> void |
isTrue(V value,
Predicate<V> predicate,
M... message)
Checks if the predicate is valid
Predicate.test() is
true . |
static <V,M> void |
isTrueRequired(V condition,
Predicate<V> predicate,
M... message)
|
static <V,M> V |
notNull(V value,
M... message)
Checks if the argument is not
null . |
static <V,M> V |
notNullState(V value,
M... message)
Checks if the argument is not
null . |
static <V,M> V |
notNullValue(Supplier<V> supplier,
M... message)
Checks if the value of a supplier is not
null without exception.. |
static <M> void |
state(boolean condition,
M... message)
If the value Checks if the argument is
true . |
public static <M> void state(boolean condition, @Nullable M... message) throws IllegalStateException
true
.IllegalStateException
- When the condtion is false@Nonnull public static <V,M> V notNullState(@Nullable V value, @Nullable M... message) throws IllegalStateException
null
.IllegalStateException
public static <M> void isTrue(boolean condition, @Nullable M... message) throws IllegalArgumentException
true
.IllegalArgumentException
public static <V,M> void isTrueRequired(@Nullable V condition, @Nonnull Predicate<V> predicate, @Nullable M... message)
public static <V,M> void isTrue(@Nullable V value, @Nonnull Predicate<V> predicate, @Nullable M... message)
true
.
An argument of the Predicable#test()
method can be null
.@Nonnull public static <V,M> Optional<V> isPresented(@Nullable V value, @Nullable M... message) throws IllegalArgumentException
Optional
object with the original valueIllegalArgumentException
@Nonnull public static <V,M> V notNull(@Nullable V value, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
@Nonnull public static <V,M> V notNullValue(@Nonnull Supplier<V> supplier, @Nullable M... message) throws IllegalArgumentException
null
without exception..IllegalArgumentException
@Nonnull public static <M> byte[] hasLength(@Nullable byte[] array, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
@Nonnull public static <M> char[] hasLength(@Nullable char[] array, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
@Nonnull public static <V,M> V[] hasLength(@Nullable V[] array, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
@Nonnull public static <V,M> Collection<V> hasLength(@Nullable Collection<V> value, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
@Nonnull public static <V,K,M> Map<K,V> hasLength(@Nullable Map<K,V> value, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
@Nonnull public static <V extends CharSequence,M> V hasLength(@Nullable V value, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static void isFalse(boolean condition, @Nullable Object... message) throws IllegalArgumentException
false
.IllegalArgumentException
public static <V,M> void isFalseRequired(@Nullable V value, @Nonnull Predicate<V> predicate, @Nullable M... message)
public static <V,M> void isFalse(@Nullable V value, @Nonnull Predicate<V> predicate, @Nullable M... message)
false
.
An argument of the Predicable#test()
method can be null
.public static <M> void isNull(@Nullable Object value, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static <M> void isEmpty(byte[] array, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static <M> void isEmpty(@Nullable char[] array, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static <V,M> void isEmpty(@Nullable V[] values, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static <M> void isEmpty(@Nullable Collection<?> values, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static <M> void isEmpty(@Nullable Map<?,?> values, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
public static <M> void isEmpty(@Nullable CharSequence value, @Nullable M... message) throws IllegalArgumentException
null
.IllegalArgumentException
Copyright 2019-2022, Pavel Ponec