Java Integer Clamp clamp(int a, int x, int y)

Here you can find the source of clamp(int a, int x, int y)

Description

clamp

License

Apache License

Declaration

public static int clamp(int a, int x, int y) 

Method Source Code

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

public class Main {
    public static int clamp(int a, int x, int y) {
        if (x > y) {
            int m = x;
            y = x;/*from ww  w  . j  a  v a  2s . c o m*/
            x = m;
        }
        return Math.max(x, Math.min(y, a));
    }

    public static float clamp(float a, float x, float y) {
        if (x > y) {
            float m = x;
            y = x;
            x = m;
        }
        return Math.max(x, Math.min(y, a));
    }

    public static double clamp(double a, double x, double y) {
        if (x > y) {
            double m = x;
            y = x;
            x = m;
        }
        return Math.max(x, Math.min(y, a));
    }
}

Related

  1. clamp(final int min, final int x, final int max)
  2. clamp(final int value, final int min, final int max)
  3. clamp(final int value, final int min, final int max)
  4. clamp(int a)
  5. clamp(int a, int x, int b)
  6. clamp(int amt, int low, int high)
  7. clamp(int c)
  8. clamp(int c)
  9. clamp(int floor, int ceiling, int value)