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 Bitmap addPadding(@NonNull Bitmap bmp) {

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

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

From source file:Main.java

public static void RGBtoHSL(int r, int g, int b, float[] hsl) {
    final float rf = r / 255f;
    final float gf = g / 255f;
    final float bf = b / 255f;

    final float max = Math.max(rf, Math.max(gf, bf));
    final float min = Math.min(rf, Math.min(gf, bf));
    final float deltaMaxMin = max - min;

    float h, s;//w w w .  j a  va 2 s  .co  m
    float l = (max + min) / 2f;

    if (max == min) {
        // Monochromatic
        h = s = 0f;
    } else {
        if (max == rf) {
            h = ((gf - bf) / deltaMaxMin) % 6f;
        } else if (max == gf) {
            h = ((bf - rf) / deltaMaxMin) + 2f;
        } else {
            h = ((rf - gf) / deltaMaxMin) + 4f;
        }

        s = deltaMaxMin / (1f - Math.abs(2f * l - 1f));
    }

    hsl[0] = (h * 60f) % 360f;
    hsl[1] = s;
    hsl[2] = l;
}

From source file:Main.java

public static int darker(int color) {

    double factor = 0.75;

    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 final float bringToBounds(final float pMinValue, final float pMaxValue, final float pValue) {
    return Math.max(pMinValue, Math.min(pMaxValue, pValue));
}

From source file:Main.java

public static float adjust(final float value, final float min, final float max) {
    return Math.min(Math.max(min, value), max);
}

From source file:Main.java

public static String getFileExtension(String fileName) {
    int i = fileName.lastIndexOf('.');
    int p = Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'));
    if (i > p) {
        return fileName.substring(i + 1);
    }/*from  ww w  .  j av  a  2s  . co  m*/
    return "";
}

From source file:Main.java

public static int[] getMaxAndSum(Map<DateMidnight, Integer> map) {
    int max = 0;/*  w w w  .  j a  v  a  2  s  .  c om*/
    int sum = 0;
    for (Integer count : map.values()) {
        sum += count;
        max = Math.max(max, count);
    }

    return new int[] { max, sum };
}

From source file:Main.java

/**
 * Round double value with low error//from w w  w.j  a v a  2 s  .  c  o m
 *
 * @param value  Value
 * @param places decimal
 * @return double
 */
static double round(double value, int places) {
    // check if places below 0
    places = Math.max(0, places);
    BigDecimal bd = new BigDecimal(value);
    bd = bd.setScale(places, RoundingMode.HALF_UP);
    return bd.doubleValue();
}

From source file:Main.java

public static int computeSampleSize(BitmapFactory.Options options, int target) {
    int w = options.outWidth;
    int h = options.outHeight;
    int candidateW = w / target;
    int candidateH = h / target;
    int candidate = Math.max(candidateW, candidateH);
    if (candidate == 0) {
        return 1;
    }/*  w w w  . j a v  a  2 s  .c  o  m*/
    if (candidate > 1) {
        if ((w > target) && (w / candidate) < target) {
            candidate -= 1;
        }
    }
    if (candidate > 1) {
        if ((h > target) && (h / candidate) < target) {
            candidate -= 1;
        }
    }
    return candidate;
}

From source file:Main.java

public static <T> Collection<? extends T> split(Collection<? extends T> d, int n) {
    Collection<T> tmp = new ArrayList<>();
    Iterator it = d.iterator();//from   w  w  w  .  j  a va 2s .c  o  m
    int k = Math.max(0, n);
    while (it.hasNext() && k > 0) {
        tmp.add((T) it.next());
        k--;
    }
    return tmp;
}