Java Integer Clamp clamp(int val, int min, int max)

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

Description

clamp

License

Open Source License

Declaration

public static int clamp(int val, int min, int max) 

Method Source Code

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

public class Main {
    public static int clamp(int val, int min, int max) {
        val = Math.min(val, max);
        val = Math.max(val, min);

        return val;
    }//from w  ww. j  av a2 s .c o m

    public static float clamp(float val, float min, float max) {
        val = Math.min(val, max);
        val = Math.max(val, min);

        return val;
    }

    public static long clamp(long val, long min, long max) {
        val = Math.min(val, max);
        val = Math.max(val, min);

        return val;
    }

    public static double clamp(double val, double min, double max) {
        val = Math.min(val, max);
        val = Math.max(val, min);

        return val;
    }

    public static short clamp(short val, short min, short max) {
        val = (short) Math.min(val, max);
        val = (short) Math.max(val, min);

        return val;
    }
}

Related

  1. clamp(int number, int low, int high)
  2. clamp(int ptr, int size)
  3. clamp(int v, int min, int max)
  4. clamp(int v, int min, int max)
  5. clamp(int v, int min, int max)
  6. clamp(int value, final int minimum, final int maximum)
  7. clamp(int value, int a, int b)
  8. clamp(int value, int low, int high)
  9. clamp(int value, int low, int high)