Here you can find the source of clamp(int v, int min, int max)
public static final int clamp(int v, int min, int max)
//package com.java2s; public class Main { public static final float clamp(float v, float min, float max) { return Math.max(Math.min(v, max), min); }//from w w w . j av a 2s.c om public static final int clamp(int v, int min, int max) { return Math.max(Math.min(v, max), min); } }