Here you can find the source of clampInt(int value, int min, int max)
Parameter | Description |
---|---|
value | the int . |
min | the minimum value. |
max | the maximum value. |
public static int clampInt(int value, int min, int max)
//package com.java2s; /*// w w w. j ava2s . com * Copyright (C) 2014 Celestibytes * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by the Free * Software Foundation; either version 3 of the License, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. */ public class Main { /** * Clamps an {@code int} between the given minimum and maximum values. * * @param value * the {@code int}. * @param min * the minimum value. * @param max * the maximum value. * @return the clamped {@code int}. */ public static int clampInt(int value, int min, int max) { return value < min ? min : value > max ? max : value; } /** * Clamps an {@code int} between {@code 0} and the given maximum value. * * @param value * the {@code int}. * @param max * the maximum value. * @return the clamped {@code int}. */ public static int clampInt(int value, int max) { return clampInt(value, 0, max); } }