/*
 * Copyright 2017, OnGres.
 *
 * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
 * following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
 * disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
 * following disclaimer in the documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */


package com.ongres.scram.common.util;


/**
 * Simple methods similar to Precondition class. Avoid importing full library.
 */
public class Preconditions {
    /**
     * Checks that the argument is not null.
     * @param value The value to be checked
     * @param <T> The type of the value
     * @return The same value passed as argument
     * @throws IllegalArgumentException If value is null
     */
    public static <T> T checkNotNull(T value, String valueName) throws IllegalArgumentException {
        if(null == value) {
            throw new IllegalArgumentException("Null value for '" + valueName + "'");
        }

        return value;
    }

    /**
     * Checks that the integer argument is positive
     * @param value The value to be checked
     * @return The same value passed as argument
     * @throws IllegalArgumentException If value is null
     */
    public static int gt0(int value, String valueName) throws IllegalArgumentException {
        if(value <= 0) {
            throw new IllegalArgumentException("'" + valueName + "' must be positive");
        }

        return value;
    }
}

@@ -1561,32 +1561,108 @@
 e to be checked%0A
+     * @param valueName The name of the value that is checked in the method%0A
      * @param %3CT
@@ -1685,16 +1685,16 @@
 e value%0A
-
      * @
@@ -2047,24 +2047,508 @@
 lue;%0A    %7D%0A%0A
+    /**%0A     * Checks that the argument is valid, based in a check boolean condition.%0A     * @param check The boolean check%0A     * @param valueName The name of the value that is checked in the method%0A     * @throws IllegalArgumentException%0A     */%0A    public static void checkArgument(boolean check, String valueName) throws IllegalArgumentException %7B%0A        if(! check) %7B%0A            throw new IllegalArgumentException(%22Argument '%22 + valueName + %22' is not valid%22);%0A        %7D%0A    %7D%0A%0A
     /**%0A    
@@ -2594,16 +2594,17 @@
 positive
+.
 %0A     * 
@@ -2632,32 +2632,108 @@
 e to be checked%0A
+     * @param valueName The name of the value that is checked in the method%0A
      * @return T

Add new method Preconditions.checkArgument()