package net.ihiroky.niotty.util;

/**
 * Provides utility methods for checking arguments of a method.
 */
public final class Arguments {

    private Arguments() {
        throw new AssertionError();
    }

    /**
     * Checks if the value is not null.
     * @param value the value to check
     * @param name the name of the variable
     * @param <T> the type of the value
     * @return the value
     * @throws NullPointerException if the value is null
     */
    public static <T> T requireNonNull(T value, String name) {
        if (value == null) {
            throw (name != null)
                    ? new NullPointerException("The " + name + " must not be null.")
                    : new NullPointerException();
        }
        return value;
    }

    /**
     * Checks if the int value is positive.
     * @param value the value to check
     * @param name the name of the variable
     * @return the value
     * @throws IllegalArgumentException if the value is not positive
     */
    public static int requirePositive(int value, String name) {
        if (value <= 0) {
            throw (name != null)
                    ? new IllegalArgumentException("The " + name + " must be positive.")
                    : new IllegalArgumentException();
        }
        return value;
    }

    /**
     * Checks if the long value is positive.
     * @param value the value to check
     * @param name the name of the variable
     * @return the value
     * @throws IllegalArgumentException if the value is not positive
     */
    public static long requirePositive(long value, String name) {
        if (value <= 0L) {
            throw (name != null)
                    ? new IllegalArgumentException("The " + name + " must be positive.")
                    : new IllegalArgumentException();
        }
        return value;
    }

    /**
     * Checks if the int value is positive or zero.
     * @param value the value to check
     * @param name the name of the variable
     * @return the value
     * @throws IllegalArgumentException if the value is negative
     */
    public static int requirePositiveOrZero(int value, String name) {
        if (value < 0) {
            throw (name != null)
                    ? new IllegalArgumentException("The " + name + " must be positive or zero.")
                    : new IllegalArgumentException();
        }
        return value;
    }

    /**
     * Checks if the long value is positive or zero.
     * @param value the value to check
     * @param name the name of the variable
     * @return the value
     * @throws IllegalArgumentException if the value is negative
     */
    public static long requirePositiveOrZero(long value, String name) {
        if (value < 0L) {
            throw (name != null)
                    ? new IllegalArgumentException("The " + name + " must be positive or zero.")
                    : new IllegalArgumentException();
        }
        return value;
    }

    /**
     * Checks if the int value is in the specified range.
     *
     * @param value the value to check
     * @param name the name of the variable
     * @param start the start of the range
     * @param end the end of he range
     * @return the value
     */
    public static int requireInRange(int value, String name, int start, int end) {
        if (value < start || value > end) {
            throw (name != null)
                    ? new IllegalArgumentException("The " + name + " must be in [" + start + ", " + end + "].")
                    : new IllegalArgumentException();
        }
        return value;
    }

    /**
     * Checks if the long value is in the specified range.
     *
     * @param value the value to check
     * @param name the name of the variable
     * @param start the start of the range
     * @param end the endIndex of he range
     * @return the value
     */
    public static long requireInRange(long value, String name, long start, long end) {
        if (value < start || value > end) {
            throw (name != null)
                    ? new IllegalArgumentException("The " + name + " must be in [" + start + ", " + end + "].")
                    : new IllegalArgumentException();
        }
        return value;
    }
}

@@ -3136,39 +3136,45 @@
    * @param 
-start the start
+min the minimum value
  of the rang
@@ -3193,23 +3193,34 @@
 ram 
-end
+max
  the 
-end
+maximum value
  of 
+t
 he r
@@ -3326,22 +3326,20 @@
 int 
-start
+min
 , int 
-end
+max
 ) %7B%0A
@@ -3350,37 +3350,35 @@
     if (value %3C 
-start
+min
  %7C%7C value %3E end)
@@ -3365,35 +3365,35 @@
  min %7C%7C value %3E 
-end
+max
 ) %7B%0A            
@@ -3490,37 +3490,35 @@
 must be in %5B%22 + 
-start
+min
  + %22, %22 + end + 
@@ -3503,35 +3503,35 @@
  + min + %22, %22 + 
-end
+max
  + %22%5D.%22)%0A       
@@ -3791,23 +3791,29 @@
 ram 
-start the start
+min the minimum value
  of 
@@ -3840,28 +3840,34 @@
 ram 
-end
+max
  the 
-endIndex
+maximum value
  of 
+t
 he r
@@ -3976,23 +3976,21 @@
 ong 
-start
+min
 , long 
-end
+max
 ) %7B%0A
@@ -4009,21 +4009,19 @@
 value %3C 
-start
+min
  %7C%7C valu
@@ -4024,19 +4024,19 @@
 value %3E 
-end
+max
 ) %7B%0A    
@@ -4153,13 +4153,11 @@
 %22 + 
-start
+min
  + %22
@@ -4166,11 +4166,11 @@
 %22 + 
-end
+max
  + %22

Change argument name