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);
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 <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 <M> CharSequence |
hasLength(CharSequence value,
M... message)
Checks if the argument is not empty, nor
null. |
static <K,V,M> Map<K,V> |
hasLength(Map<K,V> value,
M... message)
Checks if the argument is not empty, nor
null. |
static <M> Object[] |
hasLength(Object[] array,
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 <M> void |
isEmpty(Object[] values,
M... 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 <V,M> void |
isFalse(V value,
Predicate<V> predicate,
M... message)
|
static <V,M> void |
isFalseNullable(V value,
Predicate<V> predicate,
M... 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 <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 void |
isTrue(boolean condition)
Checks if the argument is
true. |
static <M> void |
isTrue(boolean condition,
M... message)
Checks if the argument is
true. |
static <V,M> void |
isTrue(V condition,
Predicate<V> predicate,
M... message)
|
static <V,M> void |
isTrueNullable(V value,
Predicate<V> predicate,
M... message)
Checks if the value is result of the the method
Predicate.test() is
true. |
static <V> V |
notNull(V value)
Checks if the argument is not
null. |
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 <M> void |
validState(boolean condition,
M... message)
If the value Checks if the argument is
true. |
public static final Object[] NO_MESSAGE
public static final <M> void validState(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.IllegalStateExceptionpublic static final void isTrue(boolean condition)
throws IllegalArgumentException
true.IllegalArgumentExceptionpublic static final <M> void isTrue(boolean condition,
@Nullable
M... message)
throws IllegalArgumentException
true.IllegalArgumentExceptionpublic static <V,M> void isTrue(@Nullable V condition, @Nonnull Predicate<V> predicate, @Nullable M... message)
public static <V,M> void isTrueNullable(@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 final <V> V notNull(@Nullable V value) throws IllegalArgumentException
null.IllegalArgumentException@Nonnull public static <V,M> V notNull(@Nullable V value, @Nullable M... message) throws IllegalArgumentException
null.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 <M> Object[] hasLength(@Nullable Object[] 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 <K,V,M> Map<K,V> hasLength(@Nullable Map<K,V> value, @Nullable M... message) throws IllegalArgumentException
null.IllegalArgumentException@Nonnull public static <M> CharSequence hasLength(@Nullable CharSequence value, @Nullable M... message) throws IllegalArgumentException
null.IllegalArgumentExceptionpublic static final void isFalse(boolean condition)
throws IllegalArgumentException
false.IllegalArgumentExceptionpublic static final void isFalse(boolean condition,
@Nullable
Object... message)
throws IllegalArgumentException
false.IllegalArgumentExceptionpublic static <V,M> void isFalse(@Nullable V value, @Nonnull Predicate<V> predicate, @Nullable M... message)
public static <V,M> void isFalseNullable(@Nullable V value, @Nonnull Predicate<V> predicate, @Nullable M... message)
false.
An argument of the Predicable#test() method can be null.public static final void isNull(@Nullable Object value) throws IllegalArgumentException
null.IllegalArgumentExceptionpublic static <M> void isNull(@Nullable Object value, @Nullable M... message) throws IllegalArgumentException
null.IllegalArgumentExceptionpublic static <M> void isEmpty(byte[] array,
@Nullable
M... message)
throws IllegalArgumentException
null.IllegalArgumentExceptionpublic static <M> void isEmpty(@Nullable char[] array, @Nullable M... message) throws IllegalArgumentException
null.IllegalArgumentExceptionpublic static <M> void isEmpty(@Nullable Object[] values, @Nullable M... message) throws IllegalArgumentException
null.IllegalArgumentExceptionpublic static <M> void isEmpty(@Nullable Collection<?> values, @Nullable M... message) throws IllegalArgumentException
null.IllegalArgumentExceptionpublic static <M> void isEmpty(@Nullable Map<?,?> values, @Nullable M... message) throws IllegalArgumentException
null.IllegalArgumentExceptionpublic static <M> void isEmpty(@Nullable CharSequence value, @Nullable M... message) throws IllegalArgumentException
null.IllegalArgumentExceptionCopyright 2015, Pavel Ponec