Java Assert assertInBounds(final String param, final int value, final int min, final int max)

Here you can find the source of assertInBounds(final String param, final int value, final int min, final int max)

Description

Asserts that the specified integer is in the valid range.

License

Apache License

Parameter

Parameter Description
param A <code>String</code> that represents the name of the parameter, which becomes the exception message text if the <code>value</code> parameter is out of bounds.
value The value of the specified parameter.
min The minimum value for the specified parameter.
max The maximum value for the specified parameter.

Declaration

public static void assertInBounds(final String param, final int value, final int min, final int max) 

Method Source Code

//package com.java2s;
/**//  ww  w .  j a  v  a  2 s . c o m
 * Copyright Microsoft Corporation
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Asserts that the specified integer is in the valid range.
     * 
     * @param param
     *            A <code>String</code> that represents the name of the parameter, which becomes the exception message
     *            text if the <code>value</code> parameter is out of bounds.
     * @param value
     *            The value of the specified parameter.
     * @param min
     *            The minimum value for the specified parameter.
     * @param max
     *            The maximum value for the specified parameter.
     */
    public static void assertInBounds(final String param, final int value, final int min, final int max) {
        if (value < min || value > max) {
            throw new IllegalArgumentException(
                    String.format("The value of the parameter %s should be between %s and %s.", param, min, max));
        }
    }
}

Related

  1. assertGreaterThanOrEquals(String name, double comparedTo, double number)
  2. assertHasInterface(Class interfaceClass, Class objectClass)
  3. assertHasLength(String... params)
  4. assertHasText(String str)
  5. assertHexOrDecLongValue(String value)
  6. assertInBounds(int[] coordinates)
  7. assertIndex(final int size, final int index)
  8. assertIndex(final String s, final int index)
  9. assertIndex(int index, String msg)