Here you can find the source of clamp(T min, T val, T max)
public static <T extends Comparable<T>> T clamp(T min, T val, T max)
//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 }