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

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

Description

Clamps an int between the given minimum and maximum values.

License

Open Source License

Parameter

Parameter Description
value the int .
min the minimum value.
max the maximum value.

Return

the clamped int .

Declaration

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

Method Source Code

//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);
    }
}

Related

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