Package org.ujorm.tools
Class Assert
java.lang.Object
org.ujorm.tools.Assert
Assertion utils, where all method can throw the
IllegalArgumentException exception only.
For a message format see the MsgFormatter.format(Object[])} method description.
See the next correct asserts
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"));
-
Method Summary
Modifier and TypeMethodDescriptionstatic <M> @org.jetbrains.annotations.NotNull byte[]hasLength(@org.jetbrains.annotations.Nullable byte[] array, @Nullable M... message) Checks if the argument is not empty, nornull.static <M> @org.jetbrains.annotations.NotNull char[]hasLength(@org.jetbrains.annotations.Nullable char[] array, @Nullable M... message) Checks if the argument is not empty, nornull.static <V,M> @NotNull Collection<V> hasLength(@Nullable Collection<V> value, @Nullable M... message) Checks if the argument is not empty, nornull.static <V,K, M> @NotNull Map<K, V> Checks if the argument is not empty, nornull.static <V,M> @NotNull V[] hasLength(@Nullable V[] array, @Nullable M... message) Checks if the argument is not empty, nornull.static <V extends CharSequence,M>
VhasLength(V value, @Nullable M... message) Checks if the argument is not empty, nornull.static <M> voidisEmpty(@org.jetbrains.annotations.Nullable char[] array, @Nullable M... message) Checks if the argument is not empty, nornull.static <M> voidisEmpty(byte[] array, @Nullable M... message) Checks if the argument is not empty, nornull.static <M> voidisEmpty(@Nullable CharSequence value, @Nullable M... message) Checks if the argument is not empty, nornull.static <M> voidisEmpty(@Nullable Collection<?> values, @Nullable M... message) Checks if the argument is not empty, nornull.static <M> voidChecks if the argument is not empty, nornull.static <V,M> void isEmpty(@Nullable V[] values, @Nullable M... message) Checks if the argument is not empty, nornull.static voidChecks if the argument isfalse.static <V,M> void Checks if the predicate is invalid Predicate.test() isfalse.static <V,M> void isFalseRequired(V value, @NotNull Predicate<V> predicate, @Nullable M... message) static <M> voidChecks if the argument isnull.static <V,M> @NotNull Optional<V> isPresented(V value, @Nullable M... message) Return a result with presented value or throw an exception.static <M> voidisTrue(boolean condition, @Nullable M... message) Checks if the argument istrue.static <V,M> void Checks if the predicate is valid Predicate.test() istrue.static <V,M> void isTrueRequired(V condition, @NotNull Predicate<V> predicate, @Nullable M... message) static <V,M> V notNull(V value, @Nullable M... message) Checks if the argument is notnull.static <V,M> V notNullState(V value, @Nullable M... message) Checks if the argument is notnull.static <V,M> V notNullValue(@NotNull Supplier<V> supplier, @Nullable M... message) Checks if the value of a supplier is notnullwithout exception..static <M> voidstate(boolean condition, @Nullable M... message) If the value Checks if the argument istrue.
-
Method Details
-
state
public static <M> void state(boolean condition, @Nullable @Nullable M... message) throws IllegalStateException If the value Checks if the argument istrue.- Throws:
IllegalStateException- When the condtion is false
-
notNullState
@NotNull public static <V,M> V notNullState(@Nullable V value, @Nullable @Nullable M... message) throws IllegalStateException Checks if the argument is notnull.- Returns:
- The original value
- Throws:
IllegalStateException
-
isTrue
public static <M> void isTrue(boolean condition, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument istrue.- Throws:
IllegalArgumentException
-
isTrueRequired
public static <V,M> void isTrueRequired(@Nullable V condition, @NotNull @NotNull Predicate<V> predicate, @Nullable @Nullable M... message) -
isTrue
public static <V,M> void isTrue(@Nullable V value, @NotNull @NotNull Predicate<V> predicate, @Nullable @Nullable M... message) Checks if the predicate is valid Predicate.test() istrue. An argument of thePredicable#test()method can benull. -
isPresented
@NotNull public static <V,M> @NotNull Optional<V> isPresented(@Nullable V value, @Nullable @Nullable M... message) throws IllegalArgumentException Return a result with presented value or throw an exception.- Returns:
- An
Optionalobject with the original value - Throws:
IllegalArgumentException
-
notNull
@NotNull public static <V,M> V notNull(@Nullable V value, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument is notnull.- Returns:
- The original value
- Throws:
IllegalArgumentException
-
notNullValue
@NotNull public static <V,M> V notNullValue(@NotNull @NotNull Supplier<V> supplier, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the value of a supplier is notnullwithout exception..- Returns:
- The original value
- Throws:
IllegalArgumentException
-
hasLength
@NotNull public static <M> @org.jetbrains.annotations.NotNull byte[] hasLength(@Nullable @org.jetbrains.annotations.Nullable byte[] array, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument is not empty, nornull.- Returns:
- The original value
- Throws:
IllegalArgumentException
-
hasLength
@NotNull public static <M> @org.jetbrains.annotations.NotNull char[] hasLength(@Nullable @org.jetbrains.annotations.Nullable char[] array, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument is not empty, nornull.- Returns:
- The original value
- Throws:
IllegalArgumentException
-
hasLength
@NotNull public static <V,M> @NotNull V[] hasLength(@Nullable @Nullable V[] array, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument is not empty, nornull.- Returns:
- The original value
- Throws:
IllegalArgumentException
-
hasLength
@NotNull public static <V,M> @NotNull Collection<V> hasLength(@Nullable @Nullable Collection<V> value, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument is not empty, nornull.- Returns:
- The original value
- Throws:
IllegalArgumentException
-
hasLength
@NotNull public static <V,K, @NotNull Map<K,M> V> hasLength(@Nullable @Nullable Map<K, V> value, @Nullable @Nullable M... message) throws IllegalArgumentExceptionChecks if the argument is not empty, nornull.- Returns:
- The original value
- Throws:
IllegalArgumentException
-
hasLength
@NotNull public static <V extends CharSequence,M> V hasLength(@Nullable V value, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument is not empty, nornull.- Returns:
- The original value
- Throws:
IllegalArgumentException
-
isFalse
public static void isFalse(boolean condition, @Nullable @Nullable Object... message) throws IllegalArgumentException Checks if the argument isfalse.- Throws:
IllegalArgumentException
-
isFalseRequired
public static <V,M> void isFalseRequired(@Nullable V value, @NotNull @NotNull Predicate<V> predicate, @Nullable @Nullable M... message) -
isFalse
public static <V,M> void isFalse(@Nullable V value, @NotNull @NotNull Predicate<V> predicate, @Nullable @Nullable M... message) Checks if the predicate is invalid Predicate.test() isfalse. An argument of thePredicable#test()method can benull. -
isNull
public static <M> void isNull(@Nullable @Nullable Object value, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument isnull.- Throws:
IllegalArgumentException
-
isEmpty
public static <M> void isEmpty(byte[] array, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument is not empty, nornull.- Throws:
IllegalArgumentException
-
isEmpty
public static <M> void isEmpty(@Nullable @org.jetbrains.annotations.Nullable char[] array, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument is not empty, nornull.- Throws:
IllegalArgumentException
-
isEmpty
public static <V,M> void isEmpty(@Nullable @Nullable V[] values, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument is not empty, nornull.- Throws:
IllegalArgumentException
-
isEmpty
public static <M> void isEmpty(@Nullable @Nullable Collection<?> values, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument is not empty, nornull.- Throws:
IllegalArgumentException
-
isEmpty
public static <M> void isEmpty(@Nullable @Nullable Map<?, ?> values, @Nullable @Nullable M... message) throws IllegalArgumentExceptionChecks if the argument is not empty, nornull.- Throws:
IllegalArgumentException
-
isEmpty
public static <M> void isEmpty(@Nullable @Nullable CharSequence value, @Nullable @Nullable M... message) throws IllegalArgumentException Checks if the argument is not empty, nornull.- Throws:
IllegalArgumentException
-