package com.github.msemys.esjc.util;

public class Preconditions {

    public static <T> T checkNotNull(T reference, String errorMessage) {
        if (reference == null) {
            throw new NullPointerException(errorMessage);
        }
        return reference;
    }

    public static <T> T checkNotNull(T reference, String errorMessage, Object... errorMessageArgs) {
        return checkNotNull(reference, String.format(errorMessage, errorMessageArgs));
    }

    public static void checkArgument(boolean expression, String errorMessage) {
        if (!expression) {
            throw new IllegalArgumentException(errorMessage);
        }
    }

    public static void checkArgument(boolean expression, String errorMessage, Object... errorMessageArgs) {
        checkArgument(expression, String.format(errorMessage, errorMessageArgs));
    }

    public static void checkState(boolean expression, String errorMessage) {
        if (!expression) {
            throw new IllegalStateException(errorMessage);
        }
    }

    public static void checkState(boolean expression, String errorMessage, Object... errorMessageArgs) {
        checkState(expression, String.format(errorMessage, errorMessageArgs));
    }

}

@@ -381,39 +381,76 @@
     
-return checkNotNull(reference, 
+if (reference == null) %7B%0A            throw new NullPointerException(
 Stri
@@ -485,32 +485,68 @@
 rMessageArgs));%0A
+        %7D%0A        return reference;%0A
     %7D%0A%0A    publi
@@ -842,34 +842,74 @@
     
-checkArgument(expression, 
+if (!expression) %7B%0A            throw new IllegalArgumentException(
 Stri
@@ -948,24 +948,34 @@
 sageArgs));%0A
+        %7D%0A
     %7D%0A%0A    p
@@ -1266,31 +1266,71 @@
     
-checkState(expression, 
+if (!expression) %7B%0A            throw new IllegalStateException(
 Stri
@@ -1369,21 +1369,31 @@
 sageArgs));%0A
+        %7D%0A
     %7D%0A%0A%7D%0A

create formatted error message only when check fails