Here you can find the source of inRange(final int value, final int min, final int max, final String fieldName)
Parameter | Description |
---|---|
value | the value to be verified |
min | the minimum value (inclusive) |
max | the maximum value (inclusive) |
fieldName | the fields name (which is used a part of the exception message) |
Parameter | Description |
---|---|
IllegalArgumentException | if the given value is lower than min or greater than max |
public static int inRange(final int value, final int min, final int max, final String fieldName) throws IllegalArgumentException
//package com.java2s; /*/*from w ww . j av a 2 s. c om*/ * #%L * JavaCreed Secure Properties Encoder * %% * Copyright (C) 2012 - 2015 Java Creed * %% * 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. * #L% */ public class Main { /** * Verifies the value and fails if the given value is outside the given range. * * @param value * the value to be verified * @param min * the minimum value (inclusive) * @param max * the maximum value (inclusive) * @param fieldName * the fields name (which is used a part of the exception message) * @return the given value * @throws IllegalArgumentException * if the given value is lower than min or greater than max */ public static int inRange(final int value, final int min, final int max, final String fieldName) throws IllegalArgumentException { if (value < min || value > max) { throw new IllegalArgumentException( "The " + fieldName + " value of " + value + " is out of range: [" + min + "," + max + "]."); } return value; } }