Here you can find the source of range(T val, T min, T max)
Parameter | Description |
---|---|
val | the number being checked. |
min | the minimum value the number can be. |
max | the maximum value the number can be. |
public static <T extends Comparable<T>> T range(T val, T min, T max)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w w w. ja v a2s . c o m*/ * Clips a number so it never goes above its max number or below its minimum * number. * * @param val * the number being checked. * @param min * the minimum value the number can be. * @param max * the maximum value the number can be. * @return itself if it does not exceed its range, else it will return its * minimum or maximum number. */ public static <T extends Comparable<T>> T range(T val, T min, T max) { if (val.compareTo(min) < 0) return min; else if (val.compareTo(max) > 0) return max; else return val; } }