Java Integer Clamp clamp(int ptr, int size)

Here you can find the source of clamp(int ptr, int size)

Description

clamp

License

Apache License

Declaration

public static int clamp(int ptr, int size) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static int clamp(int ptr, int size) {
        return clamp(ptr, 0, size - 1);//for array indices
    }//from  ww w . j  a  v a 2  s . c o  m

    public static int clamp(int ptr, int min, int max) {
        if (max < min) {
            return (ptr < min) ? min : ptr;
        }
        if (max == min) {
            return min;///*or,*/ return max;
        }
        return (ptr < min) ? min : ((ptr > max) ? max : ptr);
    }

    public static double clamp(double val, double min, double max) {
        return (val < min) ? min : ((val > max) ? max : val);
    }
}

Related

  1. clamp(int n, int lower, int upper)
  2. clamp(int n, int min, int max)
  3. clamp(int n, int min, int max)
  4. clamp(int num, int min, int max)
  5. clamp(int number, int low, int high)
  6. clamp(int v, int min, int max)
  7. clamp(int v, int min, int max)
  8. clamp(int v, int min, int max)
  9. clamp(int val, int min, int max)