package org.srplib.contract;

/**
 * Helper class containing methods for checking method arguments.
 *
 * <p>Each method throws {@link IllegalArgumentException} in case of wrong argument.</p>
 *
 * @author Anton Pechinsky
 * @see Assert
 */
public class Argument {

    /**
     * Asserts that specified expression is true.
     *
     * @param expression boolean expression
     * @param messageFormat String representing message format
     * @param arguments vararg array of message format parameters.
     * @throws IllegalStateException if object is false.
     */
    public static void checkTrue(boolean expression, String messageFormat, Object... arguments) {
        if (!expression) {
            throw new IllegalArgumentException(Utils.format(messageFormat, arguments));
        }
    }

    /**
     * Asserts that specified expression is false.
     *
     * @param expression boolean expression
     * @param messageFormat String representing message format
     * @param arguments vararg array of message format parameters.
     * @throws IllegalStateException if object is false.
     */
    public static void checkFalse(boolean expression, String messageFormat, Object... arguments) {
        checkTrue(!expression, messageFormat, arguments);
    }

    /**
     * Asserts that specified object is null.
     *
     * @param object Object to test
     * @param messageFormat String representing messageFormat to pass to exception.
     * @param arguments vararg array of messageFormat format parameters.
     * @throws IllegalStateException if object is not null.
     */
    public static void checkNull(Object object, String messageFormat, Object... arguments) {
        checkTrue(object == null, messageFormat, arguments);
    }

    /**
     * Asserts that specified object is NOT null.
     *
     * @param object Object to test
     * @param messageFormat String representing messageFormat to pass to exception.
     * @param arguments vararg array of messageFormat format parameters.
     * @throws IllegalStateException if object null.
     */
    public static void checkNotNull(Object object, String messageFormat, Object... arguments) {
        checkTrue(object != null, messageFormat, arguments);
    }

    /**
     * Asserts that specified object is NOT null.
     *
     * <p>Unlike {@link #checkNotNull(Object, String, Object...)} this method produces generic error message:
     * {@code Argument '${argument}' must not be null!}
     * </p>
     *
     * @param object Object to test
     * @param argument String argument name.
     * @throws IllegalStateException if object null.
     */
    public static void checkNotNullWithGenericMessage(Object object, String argument) {
        checkNotNull(object, "Argument '%s' must not be null!", argument);
    }

    /**
     * Asserts that specified string is blank.
     *
     * @param string String to check
     * @param messageFormat String representing messageFormat to pass to exception.
     * @param arguments vararg array of messageFormat format parameters.
     * @throws IllegalStateException if object is not null.
     */
    public static void checkBlank(String string, String messageFormat, Object... arguments) {
        checkTrue(Utils.isBlank(string), messageFormat, arguments);
    }

    /**
     * Asserts that specified string is NOT blank.
     *
     * @param string String to check
     * @param messageFormat String representing messageFormat to pass to exception.
     * @param arguments vararg array of messageFormat format parameters.
     * @throws IllegalStateException if object is not null.
     */
    public static void checkNotBlank(String string, String messageFormat, Object... arguments) {
        checkTrue(!Utils.isBlank(string), messageFormat, arguments);
    }

    /**
     * Asserts that specified objects are equal.
     *
     * @param object1 Object first object
     * @param object2 Object second object
     * @param messageFormat String representing messageFormat to pass to exception.
     * @param arguments vararg array of messageFormat format parameters.
     * @throws IllegalStateException if object1 is not null.
     */
    public static void checkEqual(Object object1, Object object2, String messageFormat, Object... arguments) {
        checkTrue(Utils.equals(object1, object2), messageFormat, arguments);
    }

    /**
     * Asserts that specified objects are NOT equal.
     *
     * @param object1 Object first object
     * @param object2 Object second object
     * @param messageFormat String representing messageFormat to pass to exception.
     * @param arguments vararg array of messageFormat format parameters.
     * @throws IllegalStateException if object1 is not null.
     */
    public static void checkNotEqual(Object object1, Object object2, String messageFormat, Object... arguments) {
        checkTrue(!Utils.equals(object1, object2), messageFormat, arguments);
    }

}

@@ -530,37 +530,40 @@
  @throws Illegal
-State
+Argument
 Exception if obj
@@ -1082,37 +1082,40 @@
  @throws Illegal
-State
+Argument
 Exception if obj
@@ -1580,37 +1580,40 @@
  @throws Illegal
-State
+Argument
 Exception if obj
@@ -2082,37 +2082,40 @@
  @throws Illegal
-State
+Argument
 Exception if obj
@@ -2656,37 +2656,40 @@
  @throws Illegal
-State
+Argument
 Exception if obj
@@ -3158,37 +3158,40 @@
  @throws Illegal
-State
+Argument
 Exception if obj
@@ -3670,37 +3670,40 @@
  @throws Illegal
-State
+Argument
 Exception if obj
@@ -4233,37 +4233,40 @@
  @throws Illegal
-State
+Argument
 Exception if obj
@@ -4835,13 +4835,16 @@
 egal
-State
+Argument
 Exce
@@ -4990,32 +4990,32 @@
 . arguments) %7B%0D%0A
-
         checkTru
@@ -5086,11 +5086,443 @@
    %7D%0D%0A%0D%0A
+    /**%0D%0A     * Throws %3Ccode%3EIllegalArgumentException%3C/code%3E unconditionally.%0D%0A     *%0D%0A     * @param messageFormat String representing messageFormat to pass to exception.%0D%0A     * @param arguments vararg array of messageFormat format parameters.%0D%0A     * @throws IllegalArgumentException%0D%0A     */%0D%0A    public static void fail(String messageFormat, Object... arguments) %7B%0D%0A        checkTrue(false, messageFormat, arguments);%0D%0A    %7D%0D%0A%0D%0A
 %7D%0D%0A

Add method Argument.fail()