Java Double Number Align align(double min, double number, double max)

Here you can find the source of align(double min, double number, double max)

Description

aligns number between min and max (guarantees number stays within inclusive bounds of min and max)

License

Open Source License

Parameter

Parameter Description
min a parameter
number a parameter
max a parameter

Declaration

public static double align(double min, double number, double max) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from w w w  .j  a  v  a  2  s  .  c  om
     * aligns number between min and max (guarantees number stays within
     * inclusive bounds of min and max)
     *
     * @param min
     * @param number
     * @param max
     * @return
     */
    public static double align(double min, double number, double max) {
        return Math.min(max, Math.max(min, number));
    }

    public static int align(int min, int number, int max) {
        return Math.min(max, Math.max(min, number));
    }

    public static int min(int... values) {
        int min = Integer.MAX_VALUE;
        for (int i : values) {
            if (i < min) {
                min = i;
            }
        }
        return min;
    }

    public static int max(int... values) {
        int max = Integer.MIN_VALUE;
        for (int i : values) {
            if (i > max) {
                max = i;
            }
        }
        return max;
    }
}

Related

  1. align(double min, double number, double max)