Java Integer Clamp clamp(final int min, final int x, final int max)

Here you can find the source of clamp(final int min, final int x, final int max)

Description

Clamps the value 'x' to be in the range [min, max].

License

Open Source License

Declaration

static int clamp(final int min, final int x, final int max) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*  w  w  w .ja  v  a2 s . co  m*/
        Clamps the value 'x' to be in the range [min, max].
     */
    static int clamp(final int min, final int x, final int max) {
        if (max < min) {
            throw new IllegalArgumentException("Max is less than min");
        }
        return Math.max(min, Math.min(max, x));
    }
}

Related

  1. clamp(final int value, final int min, final int max)
  2. clamp(final int value, final int min, final int max)
  3. clamp(int a)
  4. clamp(int a, int x, int b)