Java Assert assertParameterWithinBounds(String name, long lower, long upper, long parameter)

Here you can find the source of assertParameterWithinBounds(String name, long lower, long upper, long parameter)

Description

Throw an IllegalArgumentException when a number is not within the supplied range.

License

Apache License

Parameter

Parameter Description
name Name of the parameter to use in the Exception message.
lower Lower bound (inclusive).
upper Upper bound (inclusive).
parameter The parameter to test.

Exception

Parameter Description
IllegalArgumentException Thrown when the parameter is out of bounds.

Declaration

public static void assertParameterWithinBounds(String name, long lower, long upper, long parameter) 

Method Source Code

//package com.java2s;
/*/*from ww  w  . j a  v a2  s .c o m*/
 * Copyright (C) 2014 Lable (info@lable.nl)
 *
 * 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 {
    /**
     * Throw an {@link IllegalArgumentException} when a number is not within the supplied range.
     *
     * @param name      Name of the parameter to use in the Exception message.
     * @param lower     Lower bound (inclusive).
     * @param upper     Upper bound (inclusive).
     * @param parameter The parameter to test.
     * @throws IllegalArgumentException Thrown when the parameter is out of bounds.
     */
    public static void assertParameterWithinBounds(String name, long lower, long upper, long parameter) {
        if (parameter < lower || parameter > upper) {
            throw new IllegalArgumentException(
                    String.format("Invalid %s: %d (expected: %d <= n < %d)", name, parameter, lower, upper + 1));
        }
    }
}

Related

  1. assertOffsetLengthValid(int offset, int length, int arrayLength)
  2. assertOid(final String s)
  3. assertOneBitMask(long mask)
  4. assertParameter(Class expectedClass, Object[] params, int index)
  5. assertParameterInRange(long param, long lower, long upper)
  6. assertParameterWithinBounds(String name, long lower, long upper, long parameter)
  7. assertPasswordMeetsRequirements(String password, boolean expected)
  8. assertPositive(int num, String err)
  9. assertPositive(int val, String msg)