Example usage for java.lang Math min

List of usage examples for java.lang Math min

Introduction

In this page you can find the example usage for java.lang Math min.

Prototype

@HotSpotIntrinsicCandidate
public static double min(double a, double b) 

Source Link

Document

Returns the smaller of two double values.

Usage

From source file:Main.java

static int nextInt(int a, int b) {
    return Math.min(a, b) + random.nextInt(Math.abs(a - b));
}

From source file:Main.java

static int randomNumber(int first, int second) {
    Random r = new Random();
    int bigger = Math.max(first, second);
    int smaller = Math.min(first, second);
    return r.nextInt(bigger - smaller + 1) + smaller;
}

From source file:Main.java

public static <M extends Object> M[] subArray(M[] array, int start, int end) {
    end = Math.min(array.length, end);
    if (start >= end)
        return null;

    M[] result = (M[]) Array.newInstance(array[0].getClass(), end - start);
    System.arraycopy(array, start, result, 0, result.length);

    return result;
}

From source file:Main.java

static float nextFloat(float a, float b) {
    return Math.min(a, b) + random.nextFloat() * Math.abs(a - b);
}

From source file:Main.java

/**
 * Get left value of the bounding rectangle of the given points.
 *//*from  w  w w. j  a  v  a 2s  . c  om*/
static float getRectLeft(float[] points) {
    return Math.min(Math.min(Math.min(points[0], points[2]), points[4]), points[6]);
}

From source file:Main.java

public static <K, V> Map<K, V> createMap(K[] keys, V[] values) {
    Map<K, V> m = new HashMap<K, V>();
    for (int i = 0; i < Math.min(keys.length, values.length); i++) {
        m.put(keys[i], values[i]);//from  ww  w .j a  v  a  2  s  .c om
    }
    return m;
}

From source file:Main.java

public static <T> List<T> subList(List<T> list, int fromIndex, int toIndex) {
    if (list == null)
        return null;
    return list.subList(fromIndex, Math.min(list.size(), toIndex));
}

From source file:Main.java

public static int lighten(int color, float amount) {
    float hsv[] = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[1] = Math.max(0f, Math.min(1f, hsv[1] - amount)); // saturation
    hsv[2] = Math.max(0f, Math.min(1f, hsv[2] + amount)); // brightness
    return Color.HSVToColor(hsv);
}

From source file:Main.java

/**
 * If value &gt;= max returns max. If value &lt;= min returns min. Otherwise returns value.
 *///  w w w  .  j a v a 2s.c  o m
public static int clamp(int value, int min, int max) {
    return Math.max(Math.min(value, max), min);
}

From source file:Main.java

public static int getSampleSizeAutoFitToScreen(int paramInt1, int paramInt2, int paramInt3, int paramInt4) {
    if ((paramInt2 == 0) || (paramInt1 == 0))
        return 1;
    return Math.min(Math.max(paramInt3 / paramInt1, paramInt4 / paramInt2),
            Math.max(paramInt4 / paramInt1, paramInt3 / paramInt2));
}