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:at.tuwien.ifs.commons.util.MathUtils.java

/**
 * caps a value by the given minimum value.
 * /*from   w  ww.  j  ava 2 s  .c  om*/
 * @deprecated use {@link Math#max(int, int)} instead
 */
@Deprecated
public static final int capLower(int i, int lowerCap) {
    return Math.max(i, lowerCap);
}

From source file:Main.java

public static byte[] resize(byte[] picArray, int size, boolean faceDetect) {
    if (picArray == null) {
        return null;
    }/*from   www . jav a  2 s. co m*/
    Bitmap pic = BitmapFactory.decodeByteArray(picArray, 0, picArray.length);
    if (pic == null) {
        return null;
    }

    size = Math.min(size, Math.min(pic.getHeight(), pic.getWidth()));
    if (size % 2 != 0)
        size--;
    Log.i("sizes", "old width:" + pic.getWidth() + " old height:" + pic.getHeight() + " new size:" + size);
    Bitmap scaledPic = scale(pic, size);

    int width = scaledPic.getWidth();
    int height = scaledPic.getHeight();

    //if pic is already square, we are done now
    if (width == height) {
        return bitmapToBytes(scaledPic);
    }

    PointF mid = null;
    int cropcenter;

    if (faceDetect)
        mid = findFaceMid(scaledPic);

    Bitmap out;
    if (width > height) {
        if (mid != null)
            cropcenter = Math.max(size / 2, Math.min((int) Math.floor(mid.y), width - size / 2));
        else
            cropcenter = width / 2;
        Log.i("CROPPING", "width:" + width + " center:" + cropcenter + " size:" + size + " left edge:"
                + (cropcenter - size / 2) + " right edge:" + (cropcenter + size / 2));
        out = Bitmap.createBitmap(scaledPic, cropcenter - size / 2, 0, size, size);
    } else {
        if (mid != null)
            cropcenter = Math.max(size / 2, Math.min((int) Math.floor(mid.x), height - size / 2));
        else
            cropcenter = height / 2;
        out = Bitmap.createBitmap(scaledPic, 0, 0, size, size);
    }

    return bitmapToBytes(out);
}

From source file:Main.java

@Override
public void setDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias) {
    fb.setDot(Math.max(dot, prefixLength), bias);
}

From source file:com.t3.util.math.CappedInteger.java

public void setMax(int max) {
    this.max = Math.max(max, min);
}

From source file:de.sanandrew.mods.claysoldiers.util.soldier.upgrade.lefthand.UpgradeBowl.java

@Override
public boolean onSoldierHurt(EntityClayMan clayMan, SoldierUpgradeInst upgradeInst, DamageSource source,
        MutableFloat damage) {/*from   w ww.j av  a 2  s  . c om*/
    if (!source.isUnblockable()) {
        damage.setValue(Math.max(0.5F, damage.getValue() / 2.0F));
        upgradeInst.getNbtTag().setShort(NBT_USES, (short) (upgradeInst.getNbtTag().getShort(NBT_USES) - 1));
    }

    return false;
}

From source file:info.mikaelsvensson.devtools.analysis.shared.reportprinter.PlainTextReportPrinter.java

@Override
public void printTable(PrintStream printStream, String tableHeader, int valueColumnWidth, String[] headerRow,
        Object[][] dataRows, String[] footerRow) {
    int firstColumnWidth = Math.max(headerRow != null && headerRow.length > 0 ? headerRow[0].length() : 0,
            footerRow != null && footerRow.length > 0 ? footerRow[0].length() : 0);
    for (Object[] row : dataRows) {
        if (row != null) {
            firstColumnWidth = Math.max(firstColumnWidth, row[0].toString().length());
        }//  w  w  w  .  j  ava2  s. c  om
    }
    if (tableHeader != null) {
        printHeader(tableHeader, true, printStream);
    }
    String rowFormat = "%-" + (firstColumnWidth + 1) + "s"
            + StringUtils.repeat("%" + valueColumnWidth + "s",
                    dataRows != null && dataRows.length > 0 ? dataRows[0].length - 1 : headerRow.length - 1)
            + "\n";
    if (headerRow != null) {
        printStream.format(rowFormat, headerRow);
    }
    if (dataRows != null) {
        for (Object[] row : dataRows) {
            if (row != null) {
                for (int i = 0; i < row.length; i++) {
                    row[i] = ToStringUtil.toString(row[i]);
                }
                if (row != null) {
                    printStream.format(rowFormat, row);
                }
            }
        }
    }
    if (footerRow != null) {
        printStream.format(rowFormat, footerRow);
    }
}

From source file:Main.java

/**
 *  Convert HSL values to a RGB Color.//from   w w  w  .  j  a v a2s  . c  o m
 *
 *  @param h Hue is specified as degrees in the range 0 - 360.
 *  @param s Saturation is specified as a percentage in the range 1 - 100.
 *  @param l Lumanance is specified as a percentage in the range 1 - 100.
 *  @paran alpha  the alpha value between 0 - 1
 *  adapted from https://svn.codehaus.org/griffon/builders/gfxbuilder/tags/GFXBUILDER_0.2/
 *  gfxbuilder-core/src/main/com/camick/awt/HSLColor.java
 */
public static int[] HSLtoRGB(float h, float s, float l, float alpha) {
    if (s < 0.0f || s > 100.0f) {
        String message = "Color parameter outside of expected range - Saturation";
        throw new IllegalArgumentException(message);
    }

    if (l < 0.0f || l > 100.0f) {
        String message = "Color parameter outside of expected range - Luminance";
        throw new IllegalArgumentException(message);
    }

    if (alpha < 0.0f || alpha > 1.0f) {
        String message = "Color parameter outside of expected range - Alpha";
        throw new IllegalArgumentException(message);
    }

    //  Formula needs all values between 0 - 1.

    h = h % 360.0f;
    h /= 360f;
    s /= 100f;
    l /= 100f;

    float q = 0;

    if (l < 0.5)
        q = l * (1 + s);
    else
        q = (l + s) - (s * l);

    float p = 2 * l - q;

    int r = Math.round(Math.max(0, HueToRGB(p, q, h + (1.0f / 3.0f)) * 256));
    int g = Math.round(Math.max(0, HueToRGB(p, q, h) * 256));
    int b = Math.round(Math.max(0, HueToRGB(p, q, h - (1.0f / 3.0f)) * 256));

    return new int[] { r, g, b };
}

From source file:Main.java

/**
 *  Convert HSL values to a RGB Color./*from w  w w. j  a  va  2 s  . co  m*/
 *
 *  @param h Hue is specified as degrees in the range 0 - 360.
 *  @param s Saturation is specified as a percentage in the range 1 - 100.
 *  @param l Lumanance is specified as a percentage in the range 1 - 100.
 *  @paran alpha  the alpha value between 0 - 1
 *  adapted from https://svn.codehaus.org/griffon/builders/gfxbuilder/tags/GFXBUILDER_0.2/
 *  gfxbuilder-core/src/main/com/camick/awt/HSLColor.java
 */
public static int[] HSLtoRGB(float h, float s, float l, float alpha) {
    if (s < 0.0f || s > 100.0f) {
        String message = "Color parameter outside of expected range - Saturation";
        throw new IllegalArgumentException(message);
    }

    if (l < 0.0f || l > 100.0f) {
        String message = "Color parameter outside of expected range - Luminance";
        throw new IllegalArgumentException(message);
    }

    if (alpha < 0.0f || alpha > 1.0f) {
        String message = "Color parameter outside of expected range - Alpha";
        throw new IllegalArgumentException(message);
    }

    //  Formula needs all values between 0 - 1.

    h = h % 360.0f;
    h /= 360f;
    s /= 100f;
    l /= 100f;

    float q = 0;

    if (l < 0.5)
        q = l * (1 + s);
    else
        q = (l + s) - (s * l);

    float p = 2 * l - q;

    int r = Math.round(Math.max(0, HueToRGB(p, q, h + (1.0f / 3.0f)) * 256));
    int g = Math.round(Math.max(0, HueToRGB(p, q, h) * 256));
    int b = Math.round(Math.max(0, HueToRGB(p, q, h - (1.0f / 3.0f)) * 256));

    int[] array = { r, g, b };
    return array;
}

From source file:com.apexxs.neonblack.scoring.StringScorers.java

public Float getLevenshtien(String s1, String s2) {
    Integer ldScore = StringUtils.getLevenshteinDistance(s1.toLowerCase(), s2.toLowerCase());
    Float ld = (float) ldScore;

    int maxLength = Math.max(s1.length(), s2.length());

    ld = 1.0f - (ld / (float) maxLength);
    return ld;//  w w  w  .j a  v a2 s . co  m
}

From source file:org.fhcrc.cpl.viewer.mrm.Utils.java

/**
* For a given scan, within an MZ range, feed back the highest peak found.
*
* TODO: This could be faster, if necessary: we could do a binary search and then expand up and down.
*  @param scan/*from   www  .ja v a2 s . c  o  m*/
* @param minMZ
* @param maxMZ
* @return
*/
public static double getMaxIntensityForScan(MSRun.MSScan scan, double minMZ, double maxMZ) {
    double maxIntensityThisScan = 0;

    float[][] data = scan.getSpectrum();

    for (int j = 0; j < data[0].length; j++) {
        //since MZ values are monotonically increasing with j, when we
        // hit the max we can stop.
        if (data[0][j] > maxMZ)
            break;
        if (data[0][j] >= minMZ) {
            maxIntensityThisScan = Math.max(maxIntensityThisScan, data[1][j]);
        }
    }
    //_log.debug("       max intensity: scanIndex " + scanIndex + ", scanNumber " + run.getScan(scanIndex).getNum() + ", maxInt=" + maxIntensityThisScan);

    return maxIntensityThisScan;
}