Java Clamp clamp(T n, T l, T h)

Here you can find the source of clamp(T n, T l, T h)

Description

clamp

License

Open Source License

Declaration

public static <T extends Number> T clamp(T n, T l, T h) 

Method Source Code

//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));
    }
}

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 min, T val, T max)
  5. clamp(T value, T minimum, T maximum)
  6. clamp01(long value)
  7. clampAdd(long lhs, long rhs)