Java Integer Clamp clampInt(final int min, final int value, final int max)

Here you can find the source of clampInt(final int min, final int value, final int max)

Description

Clamps an integer within the bounds [min, max] by setting it the the closest bound if it not within the range.

License

Creative Commons License

Parameter

Parameter Description
min The minimum bound.
value The value to clamp.
max The maximum bound.

Return

The clamped integer.

Declaration

public static int clampInt(final int min, final int value, final int max) 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

public class Main {
    /**//from   w  w  w .  j  av  a  2  s  . c  o  m
     * Clamps an integer within the bounds [min, max] by setting it the the closest bound if it not within the range.
     * 
     * @param min
     *            The minimum bound.
     * @param value
     *            The value to clamp.
     * @param max
     *            The maximum bound.
     * @return The clamped integer.
     */
    public static int clampInt(final int min, final int value, final int max) {
        return Math.min(max, Math.max(min, value));
    }
}

Related

  1. clampColor(int c)
  2. clampColorInt(int color)
  3. CLAMPED_Wr(long ITERW, int FBZCP)
  4. clampI(int a, int min, int max)
  5. clampInt(final int min, final int max, final int value)
  6. clampInt(int value, int min, int max)
  7. clampInt(int value, int min, int max)
  8. CLAMPIS(int a, int b, int c)
  9. clampLoop(int v, int min, int max)