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

public static List<Integer> range(int from, int to) {
    List<Integer> result = new ArrayList<Integer>(Math.max(from, to) - Math.min(from, to) + 1);
    if (to > from) {
        for (int i = from; i <= to; i++)
            result.add(i);//from   w  w w  .ja v  a 2s  .co  m
    } else {
        for (int i = from; i >= to; i--)
            result.add(i);
    }
    return result;
}

From source file:Main.java

public static float fmin(final float... values) {
    float min = Float.MAX_VALUE;
    for (final float v : values) {
        min = Math.min(v, min);
    }/* w w w.  j av  a 2  s  .com*/
    return min;
}

From source file:Main.java

public static float calculateDuration(float startX, float startY, float endX, float endY, float maxDistance,
        int minDuaration, int maxDurationForFling) {
    float duation = Math.min(
            Math.max(Math.abs((endY - startY)), Math.abs((endX - startX))) / maxDistance * maxDurationForFling,
            maxDurationForFling);/*w ww  . ja v a2 s  .  co m*/
    if (duation < minDuaration) {
        return minDuaration;
    }
    if (duation > maxDurationForFling) {
        return maxDurationForFling;
    }
    return duation;
}

From source file:Main.java

/**
 * @param alpha 0...255/*from  w ww .j  a  va2 s .  c o m*/
 */
public static int setColorAlpha(int color, float alpha) {
    return Color.argb(Math.min(Math.max((int) (alpha * 255.0f), 0), 255), Color.red(color), Color.green(color),
            Color.blue(color));
}

From source file:Main.java

public static boolean[] copyOf(boolean[] original, int newLength) {
    boolean[] copy = new boolean[newLength];
    System.arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
    return copy;/*ww w.  ja  v a 2s  .co  m*/
}

From source file:Main.java

public static int computeInSampleSize(BitmapFactory.Options opts, int reqW, int reqH) {
    int width = opts.outWidth;
    int height = opts.outHeight;
    return Math.min(width / reqW, height / reqH);
}

From source file:Main.java

public static Bitmap cropCenterInside(Bitmap src, Rect rect) {
    int width = Math.min(src.getWidth(), rect.width());
    int height = Math.min(src.getHeight(), rect.height());
    int[] rowData = new int[width];
    int stride = src.getWidth();
    int x = (src.getWidth() - width) / 2;
    int y = (src.getHeight() - height) / 2;

    Bitmap dest = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);

    int delta = 0;
    while (delta < height) {
        src.getPixels(rowData, 0, stride, x, y + delta, width, 1);
        dest.setPixels(rowData, 0, stride, 0, delta, width, 1);
        delta++;//from  w w  w . j  av a2 s  .co  m
    }
    return dest;
}

From source file:Main.java

public static int levelChange(String xpath1, String xpath2) {
    String[] paths1 = split(xpath1);
    String[] paths2 = split(xpath2);
    int length = Math.min(paths1.length, paths2.length);
    int index = 0;
    while (index < length && paths1[index].equals(paths2[index])) {
        index++;//from   w  w w. j  a  v  a 2  s .  c  om
    }
    return index;
}

From source file:Main.java

public static int setColorLightness(int color, float light) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= Math.min(light, 1f); // value component
    return Color.HSVToColor(hsv);
}

From source file:Main.java

public static <A> List<A> take(List<A> list, int n) {
    List<A> result = new ArrayList<A>();
    for (int j = 0; j < Math.min(n, list.size()); ++j)
        result.add(list.get(j));//from  ww  w  .  j  a  v  a 2s.com
    return result;
}