Java Clamp clamp(T min, T val, T max)

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

Description

clamp

License

Apache License

Declaration

public static <T extends Comparable<T>> T clamp(T min, T val, T max) 

Method Source Code

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

public class Main {
    public static <T extends Comparable<T>> T clamp(T min, T val, T max) {
        return (val.compareTo(min) < 0) ? min : (val.compareTo(max) > 0) ? max : val;
    }//ww  w  .java 2  s. c om
}

Related

  1. clamp(final short value, final short lower, final short upper)
  2. clamp(final T MIN, final T MAX, final T VALUE)
  3. clamp(final T MIN, final T MAX, final T VALUE)
  4. clamp(T n, T l, T h)
  5. clamp(T value, T minimum, T maximum)
  6. clamp01(long value)
  7. clampAdd(long lhs, long rhs)