Here you can find the source of rangeCheck(final int value, final int min, final int max)
public static int rangeCheck(final int value, final int min, final int max)
//package com.java2s; /**//from w w w . j ava2s. c o m * Copyright 2005-2012 Akiban Technologies, Inc. * * 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 { final static String SPACES = " "; public static int rangeCheck(final int value, final int min, final int max) { if (value >= min && value <= max) { return value; } if (min == Integer.MIN_VALUE) { throw new IllegalArgumentException( String.format("Value must be less than or equals to %,d: %,d", max, value)); } if (max == Integer.MAX_VALUE) { throw new IllegalArgumentException( String.format("Value must be greater than or equal to %,d: %,d", min, value)); } else { throw new IllegalArgumentException( String.format("Value must be between %d and %d, inclusive: ", min, max, value)); } } public static long rangeCheck(final long value, final long min, final long max) { if (value >= min && value <= max) { return value; } if (min == Long.MIN_VALUE) { throw new IllegalArgumentException( String.format("Value must be less than or equals to %,d: %,d", max, value)); } if (max == Long.MAX_VALUE) { throw new IllegalArgumentException( String.format("Value must be greater than or equal to %,d: %,d", min, value)); } else { throw new IllegalArgumentException( String.format("Value must be between %d and %d, inclusive: ", min, max, value)); } } public static float rangeCheck(final float value, final float min, final float max) { if (value >= min && value <= max) { return value; } if (min == Float.MIN_VALUE) { throw new IllegalArgumentException( String.format("Value must be less than or equals to %,f: %,f", max, value)); } if (max == Float.MAX_VALUE) { throw new IllegalArgumentException( String.format("Value must be greater than or equal to %,f: %,f", min, value)); } else { throw new IllegalArgumentException( String.format("Value must be between %f and %f, inclusive: ", min, max, value)); } } public static String format(final String s, final int width, final boolean right) { final int pad = width - s.length(); if (pad < 0) return s.substring(0, width - 1) + "&"; if (pad == 0) return s; if (right) return SPACES.substring(0, pad) + s; else return s + SPACES.substring(0, pad); } public static String format(final int i) { return format(i, 10); } public static String format(final long i) { return format(i, 22); } public static String format(final long i, final int width) { return format(Long.toString(i), width, true); } public static String toString(final Object object) { return object == null ? null : object.toString(); } }