Here you can find the source of clamp(final double value, final double min, final double max)
public static double clamp(final double value, final double min, final double max)
//package com.java2s; //License from project: LGPL public class Main { public static double clamp(final double value, final double min, final double max) { if (min > max) { throw new IllegalArgumentException("min > max"); }//from ww w . j a v a2 s . com if (value < min) { return min; } else if (value > max) { return max; } else { return value; } } public static float clamp(final float value, final float min, final float max) { if (min > max) { throw new IllegalArgumentException("min > max"); } if (value < min) { return min; } else if (value > max) { return max; } else { return value; } } public static int clamp(final int value, final int min, final int max) { if (min > max) { throw new IllegalArgumentException("min > max"); } if (value < min) { return min; } else if (value > max) { return max; } else { return value; } } public static long clamp(final long value, final long min, final long max) { if (min > max) { throw new IllegalArgumentException("min > max"); } if (value < min) { return min; } else if (value > max) { return max; } else { return value; } } }