Class Assert

java.lang.Object
org.ujorm.tools.Assert

public abstract class Assert extends Object
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"));
 
Since:
1.73
Author:
Pavel Ponec
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static <M> @org.jetbrains.annotations.NotNull byte[]
    hasLength(@org.jetbrains.annotations.Nullable byte[] array, @Nullable M... message)
    Checks if the argument is not empty, nor null.
    static <M> @org.jetbrains.annotations.NotNull char[]
    hasLength(@org.jetbrains.annotations.Nullable char[] array, @Nullable M... message)
    Checks if the argument is not empty, nor null.
    static <V, M> @NotNull Collection<V>
    hasLength(@Nullable Collection<V> value, @Nullable M... message)
    Checks if the argument is not empty, nor null.
    static <V, K, M> @NotNull Map<K,V>
    hasLength(@Nullable Map<K,V> value, @Nullable M... message)
    Checks if the argument is not empty, nor null.
    static <V, M> @NotNull V[]
    hasLength(@Nullable V[] array, @Nullable M... message)
    Checks if the argument is not empty, nor null.
    static <V extends CharSequence, M>
    V
    hasLength(V value, @Nullable M... message)
    Checks if the argument is not empty, nor null.
    static <M> void
    isEmpty(@org.jetbrains.annotations.Nullable char[] array, @Nullable M... message)
    Checks if the argument is not empty, nor null.
    static <M> void
    isEmpty(byte[] array, @Nullable M... message)
    Checks if the argument is not empty, nor null.
    static <M> void
    isEmpty(@Nullable CharSequence value, @Nullable M... message)
    Checks if the argument is not empty, nor null.
    static <M> void
    isEmpty(@Nullable Collection<?> values, @Nullable M... message)
    Checks if the argument is not empty, nor null.
    static <M> void
    isEmpty(@Nullable Map<?,?> values, @Nullable M... message)
    Checks if the argument is not empty, nor null.
    static <V, M> void
    isEmpty(@Nullable V[] values, @Nullable M... message)
    Checks if the argument is not empty, nor null.
    static void
    isFalse(boolean condition, @Nullable Object... message)
    Checks if the argument is false.
    static <V, M> void
    isFalse(V value, @NotNull Predicate<V> predicate, @Nullable M... message)
    Checks if the predicate is invalid Predicate.test() is false.
    static <V, M> void
    isFalseRequired(V value, @NotNull Predicate<V> predicate, @Nullable M... message)
    Checks if the argument is not null and the predicate is invalid Predicate.test() is false.
    static <M> void
    isNull(@Nullable Object value, @Nullable M... message)
    Checks if the argument is null.
    static <V, M> @NotNull Optional<V>
    isPresented(V value, @Nullable M... message)
    Return a result with presented value or throw an exception.
    static <M> void
    isTrue(boolean condition, @Nullable M... message)
    Checks if the argument is true.
    static <V, M> void
    isTrue(V value, @NotNull Predicate<V> predicate, @Nullable M... message)
    Checks if the predicate is valid Predicate.test() is true.
    static <V, M> void
    isTrueRequired(V condition, @NotNull Predicate<V> predicate, @Nullable M... message)
    Checks if the value is not null and the predicate is valid Predicate.test() is true.
    static <V, M> V
    notNull(V value, @Nullable M... message)
    Checks if the argument is not null.
    static <V, M> V
    notNullState(V value, @Nullable M... message)
    Checks if the argument is not null.
    static <V, M> V
    notNullValue(@NotNull Supplier<V> supplier, @Nullable M... message)
    Checks if the value of a supplier is not null without exception..
    static <M> void
    state(boolean condition, @Nullable M... message)
    If the value Checks if the argument is true.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • state

      public static <M> void state(boolean condition, @Nullable @Nullable M... message) throws IllegalStateException
      If the value Checks if the argument is true.
      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 not null.
      Returns:
      The original value
      Throws:
      IllegalStateException
    • isTrue

      public static <M> void isTrue(boolean condition, @Nullable @Nullable M... message) throws IllegalArgumentException
      Checks if the argument is true.
      Throws:
      IllegalArgumentException
    • isTrueRequired

      public static <V, M> void isTrueRequired(@Nullable V condition, @NotNull @NotNull Predicate<V> predicate, @Nullable @Nullable M... message)
      Checks if the value is not null and the predicate is valid Predicate.test() is true.
    • 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() is true. An argument of the Predicable#test() method can be null.
    • 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 Optional object 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 not null.
      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 not null without 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, nor null.
      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, nor null.
      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, nor null.
      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, nor null.
      Returns:
      The original value
      Throws:
      IllegalArgumentException
    • hasLength

      @NotNull public static <V, K, M> @NotNull Map<K,V> hasLength(@Nullable @Nullable Map<K,V> value, @Nullable @Nullable M... message) throws IllegalArgumentException
      Checks if the argument is not empty, nor null.
      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, nor null.
      Returns:
      The original value
      Throws:
      IllegalArgumentException
    • isFalse

      public static void isFalse(boolean condition, @Nullable @Nullable Object... message) throws IllegalArgumentException
      Checks if the argument is false.
      Throws:
      IllegalArgumentException
    • isFalseRequired

      public static <V, M> void isFalseRequired(@Nullable V value, @NotNull @NotNull Predicate<V> predicate, @Nullable @Nullable M... message)
      Checks if the argument is not null and the predicate is invalid Predicate.test() is false.
    • 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() is false. An argument of the Predicable#test() method can be null.
    • isNull

      public static <M> void isNull(@Nullable @Nullable Object value, @Nullable @Nullable M... message) throws IllegalArgumentException
      Checks if the argument is null.
      Throws:
      IllegalArgumentException
    • isEmpty

      public static <M> void isEmpty(byte[] array, @Nullable @Nullable M... message) throws IllegalArgumentException
      Checks if the argument is not empty, nor null.
      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, nor null.
      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, nor null.
      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, nor null.
      Throws:
      IllegalArgumentException
    • isEmpty

      public static <M> void isEmpty(@Nullable @Nullable Map<?,?> values, @Nullable @Nullable M... message) throws IllegalArgumentException
      Checks if the argument is not empty, nor null.
      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, nor null.
      Throws:
      IllegalArgumentException