Example usage for java.lang Math max

List of usage examples for java.lang Math max

Introduction

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

Prototype

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

Source Link

Document

Returns the greater of two double values.

Usage

From source file:Main.java

public static int largestList(Collection<? extends Collection> cs) {
    if (cs.isEmpty())
        return -1;
    int large = 0;
    for (Collection c : cs) {
        large = Math.max(large, c.size());
    }//from w w w . j  av a2  s .  co  m
    return large;
}

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);//from w  ww. j  a  va2s.c o  m
    if (duation < minDuaration) {
        return minDuaration;
    }
    if (duation > maxDurationForFling) {
        return maxDurationForFling;
    }
    return duation;
}

From source file:Main.java

public static String getMatchingThresholdToString(int value) {
    double p = -value / 12.0;
    NumberFormat nf = NumberFormat.getPercentInstance();
    nf.setMaximumFractionDigits(Math.max(0, (int) Math.ceil(-p) - 2));
    nf.setMinimumIntegerDigits(1);//from ww  w  .  j av a 2  s . com
    return nf.format(Math.pow(10, p));
}

From source file:Main.java

public static int neighbors(int[][] source, int x, int y) {
    int maxX = Math.min(source[0].length - 1, x + 1);
    int maxY = Math.min(source.length - 1, y + 1);
    int counter = 0;
    for (int i = Math.max(y - 1, 0); i <= maxY; i++) {
        for (int j = Math.max(x - 1, 0); j <= maxX; j++) {

            if (j != x || i != y) {
                counter += source[i][j];
            }//from  ww w  .j a  va2  s. c o  m
        }
    }

    return counter;
}

From source file:Main.java

public static String[] getContextWindow(String[] a, int index, int windowSize) {
    ArrayList<String> toReturnAL = new ArrayList<String>();

    int begin = Math.max(0, index - windowSize);
    int end = Math.min(a.length, index + windowSize + 1);

    for (int i = begin; i < end; i++) {
        if (i == index)
            toReturnAL.add("[h]" + a[i] + "[/h]");
        else//from   w w  w  . ja  va  2s  .  co  m
            toReturnAL.add(a[i]);
    }

    return toReturnAL.toArray(new String[0]);
}

From source file:Main.java

/**
 * Computes Mystic Armor given an attribute value
 * @param indice the attribute value//w  w w. j  av  a2s.c om
 * @return Wound Threshold for the given attribute value
 */
public static int computeMysticArmor(final int indice) {
    return (int) Math.ceil(Math.max(indice - 10, 0) / 3.0);
}

From source file:Main.java

public static int[] scaleImageSize(int[] img_size, int square_size) {
    if (img_size[0] <= square_size && img_size[1] <= square_size)
        return img_size;
    double ratio = square_size / (double) Math.max(img_size[0], img_size[1]);
    return new int[] { (int) (img_size[0] * ratio), (int) (img_size[1] * ratio) };
}

From source file:Main.java

/**
 * @param numBits//  w w w  .j  a v a  2 s  .  co m
 * @param bitsPerDigit
 * @return
 */
private static int getNumDigits(final int numBits, final int bitsPerDigit) {
    int numDigits = (numBits / bitsPerDigit) + ((numBits % bitsPerDigit) == 0 ? 0 : 1);
    numDigits = Math.max(1, numDigits);
    return numDigits;
}

From source file:Main.java

public static int get18DarkColor(int color, float factor) {
    int a = Color.alpha(color);
    int r = Color.red(color);
    int g = Color.green(color);
    int b = Color.blue(color);

    return Color.argb(a, Math.max((int) (r * factor), 0), Math.max((int) (g * factor), 0),
            Math.max((int) (b * factor), 0));
}

From source file:Main.java

public static Bitmap addPadding(Bitmap bmp, int color) {

    if (bmp == null) {
        return null;
    }/*from   w  ww  .  j  a va2s .  c  om*/

    int biggerParam = Math.max(bmp.getWidth(), bmp.getHeight());
    Bitmap bitmap = Bitmap.createBitmap(biggerParam, biggerParam, bmp.getConfig());
    Canvas canvas = new Canvas(bitmap);
    canvas.drawColor(color);

    int top = bmp.getHeight() > bmp.getWidth() ? 0 : (bmp.getWidth() - bmp.getHeight()) / 2;
    int left = bmp.getWidth() > bmp.getHeight() ? 0 : (bmp.getHeight() - bmp.getWidth()) / 2;

    canvas.drawBitmap(bmp, left, top, null);
    return bitmap;
}