Java Number Range Check inRange(int value, int min, int max)

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

Description

Brings an integer into a specified range.

License

Open Source License

Parameter

Parameter Description
value The value to bring into the range.
min The minimum value, inclusive.
max The maximum value, inclusive.

Return

The in-bounded value.

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   w  ww.ja va2s.c  o  m*/
     * Brings an integer into a specified range.
     *
     * @param value The value to bring into the range.
     * @param min The minimum value, inclusive.
     * @param max The maximum value, inclusive.
     * @return The in-bounded value.
     */
    public static int inRange(int value, int min, int max) {
        return value < min ? min : value > max ? max : value;
    }

    /**
     * Brings an integer into a specified range.
     *
     * @param value The value to bring into the range.
     * @param min The minimum value, inclusive.
     * @param max The maximum value, inclusive.
     * @return The in-bounded value.
     */
    public static float inRange(float value, float min, float max) {
        return value < min ? min : value > max ? max : value;
    }

    /**
     * Brings an integer into a specified range.
     *
     * @param value The value to bring into the range.
     * @param min The minimum value, inclusive.
     * @param max The maximum value, inclusive.
     * @return The in-bounded value.
     */
    public static double inRange(double value, double min, double max) {
        return value < min ? min : value > max ? max : value;
    }
}

Related

  1. inRange(int n, int lo, int hi)
  2. inRange(int num, int from, int to, int flag)
  3. inRange(int value, int lowerBound, int upperBound)
  4. inRange(int value, int min, int max)
  5. inRange(int value, int min, int max)
  6. inRange(int value, int min, int max)
  7. inRange(int x, int a, int b)
  8. inRange(Integer x1, Integer y1, Integer x2, Integer y2)
  9. inRange(long value, long lowerBound, long upperBound)