Here you can find the source of clamp(int number, int low, int high)
Parameter | Description |
---|---|
number | The number to clamp. |
low | The lower bound. |
high | The higher bound. |
public static int clamp(int number, int low, int high)
//package com.java2s; /*//from w w w. jav a2s . c o m * DoomManager * Copyright (C) 2014 Chris K * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU 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. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Returns a number clamped between low and high inclusive. If low is not * the lower of the low/high, it will be set via this method. * * @param number * The number to clamp. * * @param low * The lower bound. * * @param high * The higher bound. * * @return * The clamped number. */ public static int clamp(int number, int low, int high) { if (low == high) return low; int _low = Math.min(low, high); int _high = Math.max(low, high); return Math.min(Math.max(number, _low), _high); } }