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

/**
 * Moves the supplied <code>JSplitPane</code> divider to the specified <code>proportion</code>.
 * Valid values for <code>proportion</code> range from <code>0.0F<code>
 * to <code>1.0F</code>.  For example, a <code>proportion</code> of <code>0.3F</code> will move the
 * divider to 30% of the "size" (<i>width</i> for horizontal split, <i>height</i> for vertical split) of the
 * split container that contains the specified <code>Dockable</code>.  If a <code>proportion</code> of less
 * than <code>0.0F</code> is supplied, the value </code>0.0F</code> is used.  If a <code>proportion</code>
 * greater than <code>1.0F</code> is supplied, the value </code>1.0F</code> is used.
 * <br/>//ww w . j a v  a  2 s  .  co  m
 * This method should be effective regardless of whether the split layout in question has been fully realized
 * and is currently visible on the screen.  This should alleviate common problems associated with setting
 * percentages of unrealized <code>Component</code> dimensions, which are initially <code>0x0</code> before
 * the <code>Component</code> has been rendered to the screen.
 * <br/>
 * If the specified <code>JSplitPane</code> is <code>null</code>, then this method returns with no action
 * taken.
 *
 * @param split the <code>JSplitPane</code> whose divider location is to be set.
 * @param proportion a double-precision floating point value that specifies a percentage,
 * from zero (top/left) to 1.0 (bottom/right)
 * @see #getSplitPaneSize(JSplitPane)
 * @see JSplitPane#setDividerLocation(double)
 */
public static void setSplitDivider(final JSplitPane split, float proportion) {
    if (split == null)
        return;

    proportion = Math.max(0f, proportion);
    final float percent = Math.min(1f, proportion);
    int size = getSplitPaneSize(split);

    if (split.isVisible() && size > 0 && EventQueue.isDispatchThread()) {
        split.setDividerLocation(proportion);
        split.validate();
        return;
    }

    EventQueue.invokeLater(new Runnable() {
        public void run() {
            setSplitDivider(split, percent);
        }
    });
}

From source file:Main.java

public static String[] copyOf(String[] obj, int newSize) {
    String tempArr[] = new String[newSize];
    System.arraycopy(obj, 0, tempArr, 0, Math.min(obj.length, newSize));
    return tempArr;
}

From source file:org.jfree.chart.demo.DeviationRendererDemo3.java

private static XYDataset createDataset() {
    YIntervalSeries series1 = new YIntervalSeries("Band A");
    YIntervalSeries series2 = new YIntervalSeries("Band B");
    YIntervalSeries series3 = new YIntervalSeries("Band C");
    Object obj = new Quarter(1, 2005);
    double d = 0.0D;
    for (int i = 0; i <= 12; i++) {
        d += (Math.random() - 0.5D) * 15D;
        series1.add(((RegularTimePeriod) (obj)).getMiddleMillisecond(), d, d + 10D, Math.max(50D, d + 30D));
        series2.add(((RegularTimePeriod) (obj)).getMiddleMillisecond(), d, d - 10D, d + 10D);
        series3.add(((RegularTimePeriod) (obj)).getMiddleMillisecond(), d, Math.min(-50D, d - 30D), d - 10D);
        obj = ((RegularTimePeriod) (obj)).next();
    }// w w  w . jav a 2 s  .  com

    YIntervalSeriesCollection dataset = new YIntervalSeriesCollection();
    dataset.addSeries(series1);
    dataset.addSeries(series2);
    dataset.addSeries(series3);
    return dataset;
}

From source file:Main.java

public static int[] copyOfRange(final int[] original, final int from, final int to) {
    final int newLength = to - from;
    if (newLength < 0) {
        throw new IllegalArgumentException(from + " > " + to);
    }/*ww w  . ja  v a 2 s  .com*/
    final int[] copy = new int[newLength];
    System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
    return copy;
}

From source file:edu.tum.cs.vis.model.util.HandleComparator.java

/**
 * Get weight for area coverage based on sigmoid function. Area coverage should be bigger than
 * 0.5 (= 50%)//  w ww  . j a  v a  2  s. com
 * 
 * @param coverage
 *            area coverage to calculate weight for
 * @return weight for provided area coverage
 */
private static double getAreaCoverageWeight(float coverage) {
    // calculates sigmoid: 1/(1+e^(-(x-0.5)*20))
    return 1 / (1 + Math.exp(-(Math.min(coverage, 1) - 0.5) * 20)) * WEIGHT_COVERAGE;
}

From source file:de.unihannover.se.processSimulation.dataGenerator.StatisticsUtil.java

/**
 * Computes the median and its confidence interval for the given data and p-value.
 * When there is enough data, the confidence interval is conservative. The caller
 * has to ensure that there is enough data (the minimum length depens only on p, not
 * on the data)./*from  w ww .  j  a  va2 s .  co  m*/
 */
public static MedianWithConfidenceInterval median(double[] data, double p) {
    Arrays.sort(data);
    //When the array is really short, the intended p value can possibly not be reached. This is not checked here
    //  and has to be taken care of by the researcher.
    return new MedianWithConfidenceInterval(
            data.length % 2 == 0 ? ((data[data.length / 2 - 1] + data[data.length / 2]) / 2.0)
                    : data[data.length / 2],
            data[qBinom(p / 2.0, data.length, 0.5) - 1],
            data[Math.min(qBinom(1.0 - p / 2.0, data.length, 0.5), data.length - 1)]);
}

From source file:com.whizzosoftware.hobson.lifx.api.message.HSBK.java

public HSBK(int r, int g, int b) {
    float[] hsb = Color.RGBtoHSB(r, g, b, null);
    this.hue = (int) ((Math.min(hsb[0], 1.0)) * 65535);
    this.saturation = (int) ((Math.min(hsb[1], 1.0)) * 65535);
    this.brightness = (int) ((Math.min(hsb[2], 1.0)) * 65535);
    this.kelvin = DEFAULT_KELVIN;
}

From source file:Main.java

public static Bitmap fastblur(Context context, Bitmap sentBitmap, int radius) {
    Bitmap bitmap = sentBitmap.copy(sentBitmap.getConfig(), true);
    if (radius < 1) {
        return (null);
    }//from ww  w  .  ja va2  s.co m
    int w = bitmap.getWidth();
    int h = bitmap.getHeight();
    int[] pix = new int[w * h];
    bitmap.getPixels(pix, 0, w, 0, 0, w, h);
    int wm = w - 1;
    int hm = h - 1;
    int wh = w * h;
    int div = radius + radius + 1;

    int r[] = new int[wh];
    int g[] = new int[wh];
    int b[] = new int[wh];
    int rsum, gsum, bsum, x, y, i, p, yp, yi, yw;

    int vmin[] = new int[Math.max(w, h)];
    int divsum = (div + 1) >> 1;
    divsum *= divsum;
    int temp = 256 * divsum;
    int dv[] = new int[temp];
    for (i = 0; i < temp; i++) {
        dv[i] = (i / divsum);
    }

    yw = yi = 0;

    int[][] stack = new int[div][3];

    int stackpointer;

    int stackstart;

    int[] sir;

    int rbs;

    int r1 = radius + 1;

    int routsum, goutsum, boutsum;

    int rinsum, ginsum, binsum;

    for (y = 0; y < h; y++) {

        rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;

        for (i = -radius; i <= radius; i++) {

            p = pix[yi + Math.min(wm, Math.max(i, 0))];

            sir = stack[i + radius];

            sir[0] = (p & 0xff0000) >> 16;

            sir[1] = (p & 0x00ff00) >> 8;

            sir[2] = (p & 0x0000ff);

            rbs = r1 - Math.abs(i);

            rsum += sir[0] * rbs;

            gsum += sir[1] * rbs;

            bsum += sir[2] * rbs;

            if (i > 0) {

                rinsum += sir[0];

                ginsum += sir[1];

                binsum += sir[2];

            } else {

                routsum += sir[0];

                goutsum += sir[1];

                boutsum += sir[2];

            }

        }

        stackpointer = radius;

        for (x = 0; x < w; x++) {

            r[yi] = dv[rsum];

            g[yi] = dv[gsum];

            b[yi] = dv[bsum];

            rsum -= routsum;

            gsum -= goutsum;

            bsum -= boutsum;

            stackstart = stackpointer - radius + div;

            sir = stack[stackstart % div];

            routsum -= sir[0];

            goutsum -= sir[1];

            boutsum -= sir[2];

            if (y == 0) {

                vmin[x] = Math.min(x + radius + 1, wm);

            }

            p = pix[yw + vmin[x]];

            sir[0] = (p & 0xff0000) >> 16;

            sir[1] = (p & 0x00ff00) >> 8;

            sir[2] = (p & 0x0000ff);

            rinsum += sir[0];

            ginsum += sir[1];

            binsum += sir[2];

            rsum += rinsum;

            gsum += ginsum;

            bsum += binsum;

            stackpointer = (stackpointer + 1) % div;

            sir = stack[(stackpointer) % div];

            routsum += sir[0];

            goutsum += sir[1];

            boutsum += sir[2];

            rinsum -= sir[0];

            ginsum -= sir[1];

            binsum -= sir[2];

            yi++;

        }

        yw += w;

    }

    for (x = 0; x < w; x++) {

        rinsum = ginsum = binsum = routsum = goutsum = boutsum = rsum = gsum = bsum = 0;

        yp = -radius * w;

        for (i = -radius; i <= radius; i++) {

            yi = Math.max(0, yp) + x;

            sir = stack[i + radius];

            sir[0] = r[yi];

            sir[1] = g[yi];

            sir[2] = b[yi];

            rbs = r1 - Math.abs(i);

            rsum += r[yi] * rbs;

            gsum += g[yi] * rbs;

            bsum += b[yi] * rbs;

            if (i > 0) {

                rinsum += sir[0];

                ginsum += sir[1];

                binsum += sir[2];

            } else {

                routsum += sir[0];

                goutsum += sir[1];

                boutsum += sir[2];

            }

            if (i < hm) {

                yp += w;

            }

        }

        yi = x;

        stackpointer = radius;

        for (y = 0; y < h; y++) {

            pix[yi] = (0xff000000 & pix[yi]) | (dv[rsum] << 16)

                    | (dv[gsum] << 8) | dv[bsum];

            rsum -= routsum;

            gsum -= goutsum;

            bsum -= boutsum;

            stackstart = stackpointer - radius + div;

            sir = stack[stackstart % div];

            routsum -= sir[0];

            goutsum -= sir[1];

            boutsum -= sir[2];

            if (x == 0) {

                vmin[y] = Math.min(y + r1, hm) * w;

            }

            p = x + vmin[y];

            sir[0] = r[p];

            sir[1] = g[p];

            sir[2] = b[p];

            rinsum += sir[0];

            ginsum += sir[1];

            binsum += sir[2];

            rsum += rinsum;

            gsum += ginsum;

            bsum += binsum;

            stackpointer = (stackpointer + 1) % div;

            sir = stack[stackpointer];

            routsum += sir[0];

            goutsum += sir[1];

            boutsum += sir[2];

            rinsum -= sir[0];

            ginsum -= sir[1];

            binsum -= sir[2];

            yi += w;

        }

    }

    bitmap.setPixels(pix, 0, w, 0, 0, w, h);

    return (bitmap);

}

From source file:at.tuwien.ifs.commons.util.MathUtils.java

/**
 * caps a value by the given maximum value.
 * //from  w  w  w.  j av a2  s . co m
 * @deprecated use {@link Math#min(int, int)} instead.
 */
@Deprecated
public static final int cap(int i, int cap) {
    return Math.min(i, cap);
}