Here you can find the source of clamp(T n, T l, T h)
public static <T extends Number> T clamp(T n, T l, T h)
//package com.java2s; /******************************************************************************* * This file is part of AnathemaRL./*from w ww . j a v a 2 s. com*/ * * AnathemaRL is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * AnathemaRL is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with AnathemaRL. If not, see <http://www.gnu.org/licenses/>. *******************************************************************************/ public class Main { public static <T extends Number> T clamp(T n, T l, T h) { return (n.doubleValue() > h.doubleValue() ? h : (n.doubleValue() < l.doubleValue() ? l : n)); } }